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
MXrecords that are not at the highest priority and that point tomail.raksha.ch - reduce the TTL for all
MXrecords 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
phoenixand get a shell in theemailcontainer: - 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 a shell on the
estafette.ik.vps.flosstools.orgVPS)
sudo -u mailu bash -c 'cd /srv/mailu; docker compose exec db psql -h localhost -U mailu mailu'
- Paste the
INSERT INTOstances 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
emailcontainer, push the directory of your user
USER=kevin@ohsystems.io; dir=$(vmm userinfo $USER | grep "Home..." | sed -e 's/^.*: //g;s|/$||g'); rsync --rsh="ssh -i /root/.ssh/id_rsa_email -l debian" -avz $dir/ estafette.ik.vps.flosstools.org:mails-from-phoenix/$USER
- From the
estafette.ik.vps.flosstools.orgVPS, sync the emails to the mailu directory
export USER=kevin@ohsystems.io
sudo rsync -avz --no-perms --chown mail:man /home/debian/mails-from-phoenix/$USER/Maildir/ /srv/mailu/mail/$USER
- From
estafette.…, also sync the sieve scripts, if they exist:
export USER=kevin@ohsystems.io
if test -d /home/debian/mails-from-phoenix/$USER/sieve; then
sudo rsync -avz --no-perms --chown mail:man /home/debian/mails-from-phoenix/$USER/sieve /srv/mailu/mail/$USER/
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
mailcontainer: - 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_domainsto add a line for $DOMAIN - run
postmap /etc/postfix/transports/mailu_domainsto compile the file and reload postfix
- edit
- Add mail.flosstools.org as secondary MX (higher priority) in $DOMAIN's DNS
Done. Enjoy.