How to Migrate from VMM to Mailu
Lets' take an example domain, to write the docs as-we-go: example.com
.
1. DNS operations
First, you need to make sure that:
- no emails flow via Mailu (sometimes it was configured as secondary MX)
- DNS TTLs are low enough that on migration day you are not bothered by timeouts.
In other words:
- delete any
MX
records that are not at the highest priority and that point tomail.raksha.ch
- reduce the TTL for all
MX
records to 5 minutes (or 1h ondesec.io
)
The result should be something like:
$ dig +short MX example.com
10 mail.flosstools.org.
2. Check the domain requirements
- Login to
phoenix
and get a shell in theemail
container: - Execute the following commands to get an idea of the amount of emails ans aliases you'll need:
vmm domaininfo example.com
3. Domain creation on mailu
- Head to https://mail.raksha.ch/admin/domain and login as
postmaster@mail.raksha.ch
- Hit "New Domain" and fill in your numbers
- don't bother for the quota just now
- do not tick "authorize registration"
- fill in a useful comment (such as
Swisslinux.org (OdyX)
)
4. Aliases creation on mailu
- Run that command in the 'email' container:
DOMAIN=example.com
for alias in $(vmm listaliases $DOMAIN | grep '[+]' | sed -e 's/.*] //g' | grep -v 'postmaster@'); do localpart=$(echo "$alias" | cut -f1 -d@); domain=$(echo "$alias" | cut -f2 -d@); dests=""; for dest in $(vmm aliasinfo $alias | grep ' \* ' | sed -e 's/.* \* //g'); do dests="$dests,$dest"; done; dests=$(echo "$dests"| cut -c 2-); echo "INSERT INTO \"alias\" (localpart,domain_name,email,destination,created_at) VALUES ('$localpart','$domain','$alias','$dests',now());"; done
echo "INSERT INTO \"alias\" (localpart,domain_name,email,destination,created_at) VALUES ('postmaster', '$DOMAIN', 'postmaster@$DOMAIN', 'postmaster+$DOMAIN@mail.raksha.ch',now());"
That gives you a series of 'INSERT INTO' SQL commands.
- Get a PSQL shell (from the
phoenix
shell)
lxc exec mailu -- sudo -u mailu bash -c 'cd /srv/mailu; docker-compose exec db psql -h localhost -U mailu mailu'
- Paste the
INSERT INTO
stances in that psql shell; verify from the interface that the aliases make sense.
5. Migrate the actual email accounts
For each email account of the domain, do:
- Create the email account from the mailu (mail.raksha.ch) interface
- From the mailu container, run the synchronization script:
lxc exec mailu /root/sync_from_email.sh emailaddress@example.com
- Add that command to the root user on the mailu container of phoenix, with an hourly frequency
@hourly /root/sync_from_email.sh emailaddress@example.com
Mailu puller script
#!/bin/sh
set -e
EMAIL=$1
if [ -z "$EMAIL" ]; then
>&2 echo "Email is empty. Abort";
exit 1;
fi
# Get folder from email container
vmmdir=`ssh root@email vmm userinfo $EMAIL | grep Home | sed -e 's/^.*: //g;s|/$||g'`
# Check that the directory exists
ssh root@email test -d $vmmdir/Maildir
rsync -avz --no-perms --chown mail:man root@email:$vmmdir/Maildir/ /srv/mailu/mail/$EMAIL
chown mail:man /srv/mailu/mail/$EMAIL
if ssh root@email test -d $vmmdir/sieve; then
rsync -avz --no-perms --chown mail:man root@email:$vmmdir/sieve /srv/mailu/mail/$EMAIL/
fi
6. Inform your users, and give them time to check and test, announce a flag day
TODO: better explanation of what changes for users (from mail.flosstools.org to mail.raksha.ch, etc).
7. Actual migration
- Run a sync for the actual users
- Toggle the DNS records to mail.raksha.ch
- Wait for the propagation time (TTL * 2)
- On on the
mail
container: - Backup the whole domain emails
bash dir=$(vmm domaininfo $DOMAIN | grep "Domain Directory" | sed -e 's/.*: //g'); tar cvzf /root/$DOMAIN.tar.gz $dir
- Delete the email domain
bash vmm domaindelete $DOMAIN force
- Mark the domain as relayed to Mailu
- edit
/etc/postfix/transports/mailu_domains
to add a line for $DOMAIN - run
postmap /etc/postfix/transports/mailu_domains
to compile the file and reload postfix
- edit
- Add mail.flosstools.org as secondary MX (higher priority) in $DOMAIN's DNS
Done. Enjoy.