#!/bin/sh qdir="/var/qmail/queue" if [ $# != 1 ]; then echo "usage: $0 egrep_regex" exit 1 fi regex="$1" cd $qdir || exit 1 date=`date +'%Y%m%d_%H%M%S'` stamp="dequeued/$date" dq_dir="$qdir/$stamp" echo "dequeuing into $dq_dir" mkdir -p $dq_dir || exit 1 # this is so that qmailq can delete directories underneath here chmod 1777 $qdir/dequeued dirs="intd todo info local remote bounce mess" find $dirs -type d -print | cpio -pmd $stamp >/dev/null # # qmail-send has been killed, so we know that no info/NNN # will be created or deleted while we are working. trying # to do this with qmail-send still running is extremely # troublesome... so we won't even try. # # qmail-queue can still run, because it will only create # new files, and won't touch any NNN for which an info/NNN # already exists... so we won't catch any messages which # are in the process of being delivered while we dequeue # # so we first find messages with info entries, we will # only consider these messages for our queue scanning # # intd, todo and bounce are *unhashed* # local, remote, info, and mess are *hashed* # # XXX should use headergrep here instead of egrep ( cd mess; find . -type f -print ) \ | ( cd mess; xargs egrep -l -e "$regex" ) \ | /usr/bin/perl -e ' sub m { my ($a, $b) = @_; #print "rename($a, $b)\n"; rename($a, $b); } my $count; print "dequeueing: "; while (<>) { chomp; my $hash = $_; my ($unhash) = m#.*/(.*)#; &m("intd/$unhash", "'$stamp'/intd/$unhash"); &m("todo/$unhash", "'$stamp'/todo/$unhash"); &m("local/$hash", "'$stamp'/local/$hash"); &m("remote/$hash", "'$stamp'/remote/$hash"); &m("bounce/$unhash", "'$stamp'/bounce/$unhash"); &m("info/$hash", "'$stamp'/info/$hash"); &m("mess/$hash", "'$stamp'/mess/$hash"); print "$count..." if (++$count % 1000 == 0); } print; ' echo "setting permissions on $qdir/$stamp" chown -R qmailq $stamp echo "moving to /var/qmail/dequeue/$date" cd dequeued && tar cf - $date | (cd /var/qmail/dequeue; tar xpf -) \ && rm -rf $date