Skip to content

Instantly share code, notes, and snippets.

@jcbf
Last active October 1, 2017 20:41
Show Gist options
  • Save jcbf/3978e92a6bd50c122ef735ab687e225d to your computer and use it in GitHub Desktop.
Save jcbf/3978e92a6bd50c122ef735ab687e225d to your computer and use it in GitHub Desktop.
Copy postfix queue to another server
# http://postfix.1071664.n5.nabble.com/stop-receiving-mail-but-keep-processing-mail-in-queue-td92652.html#a92762
# : on old server
service pf_outb_deliver stop
export MAIL_CONFIG=/opt/config/pf_outb_deliver
name=$(postconf -xh syslog_name)
postsuper -h ALL
cd $(postconf -xh queue_directory)
umask 077
t=$(mktemp "/tmp/${name}-hold.tgz.XXXXXX")
tar czvf "$t" hold && mv "$t" "/tmp/${name}-hold.tgz"
service pf_outb_deliver start
echo Done. Saved backup in $t
# : on new server
serivce pf_outb_deliver stop
# : per Postfix instance
export MAIL_CONFIG=/opt/config/pf_outb_deliver
export name=$(postconf -xh syslog_name)
export qdir=$(postconf -xh queue_directory)
export mail_owner=$(postconf -xh mail_owner)
postsuper -H ALL
(cd "${qdir}"; tar xzvf -) < "${name}-hold.tgz"
chown -R "${mail_owner}" "${qdir}/hold"
echo Repeating "postsuper -s" until all structires are reconstructed
while postsuper -s ; do
sleep 1
done
echo release queue files from merged "hold" queue
postsuper -H ALL
echo Make sure queue content looks OK
mailq
service pf_outb_deliver start
#How would we set Postfix to stop accepting incoming mail yet keep
#processing any queued mail?
export MAIL_CONFIG=/opt/config/pf_outb_deliver
#postconf -e "inet_interfaces = loopback-only"
#service pf_outb_deliver stop
#service pf_outb_deliver start
#A less invasive change is:
postconf -e "master_service_disable = inet"
service pf_outb_deliver reload
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment