Created
March 27, 2015 08:32
-
-
Save benjamin-thomas/9c4aa42f31bdea39cab9 to your computer and use it in GitHub Desktop.
Sync all emails from one mail server to the next (iRedMail)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
function syncAccount() { | |
# Important: need trailing slash | |
FROM=$1 | |
TO=$2 | |
[[ $FROM =~ /$ ]] || (echo "Missing trailing slash!" && exit 1) | |
[[ $TO =~ /$ ]] || (echo "Missing trailing slash!" && exit 1) | |
echo -e "\033[1;33m ==> Syncing $FROM\033[0;m" | |
# NOTE: Use the --delete switch for the first syncs, during dns propagation, do not use --delete anymore | |
# --delete \ | |
rsync -Pr \ | |
--update \ | |
--owner --group --chown=vmail:vmail \ | |
$FROM $TO | |
} | |
echo -e "\033[1;33m ==> Syncing from old mail server\033[0;m" | |
# NOTE: I prefer to leave the $FROM argument rather explicit here since it's pretty clear which way the data is flowing | |
syncAccount \ | |
root@old_mail:/var/vmail/vmail1/mydomain.com/username1/ \ | |
/var/vmail/vmail1/mydomain.com/username1/ | |
syncAccount \ | |
root@old_mail:/var/vmail/vmail1/mydomain.com/username2/ \ | |
/var/vmail/vmail1/mydomain.com/username2/ | |
cd /tmp # Bypass perm error on cd into /root when using "su postgres" | |
# Reset (webmail) quotas per: http://www.iredmail.org/forum/topic5135-iredmail-support-update-quota.html | |
su postgres -c "psql vmail -c 'DELETE FROM used_quota;'" | |
echo -e "\033[1;32m ==> All done.\033[0;m" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment