Skip to content

Commit 99630e4

Browse files
hpk42missytake
andauthored
docs: streamline migration guide wording, provide titled steps (#789)
* docs: update migration guide after nine migration * use $OLD_IP4 and $NEW_IP4 to make docs more readable. Also streamline "set TTL to 5 minute" phrasing a bit. * fix tar commands * refactor: streamline and refactor the migration guide to provide more clarity and focus * recommend a "higher TTL" concrete value Co-authored-by: missytake <[email protected]> * scriptify another location --------- Co-authored-by: missytake <[email protected]>
1 parent 2f8199a commit 99630e4

File tree

1 file changed

+68
-42
lines changed

1 file changed

+68
-42
lines changed

doc/source/migrate.rst

Lines changed: 68 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,98 @@
11

2-
Migrating to a new host
3-
-----------------------
2+
Migrating to a new machine
3+
===========================
44

5-
If you want to migrate chatmail relay from an old machine to a new
6-
machine, you can use these steps. They were tested with a Linux laptop;
7-
you might need to adjust some of the steps to your environment.
5+
This migration tutorial provides a step-wise approach
6+
to safely migrate a chatmail relay from one remote machine to another.
87

9-
Let’s assume that your ``mail_domain`` is ``mail.example.org``, all
10-
involved machines run Debian 12, your old site’s IP address is
11-
``13.37.13.37``, and your new site’s IP address is ``13.12.23.42``.
8+
Preliminary notes and assumptions
9+
---------------------------------
1210

13-
Note, you should lower the TTLs of your DNS records to a value such as
14-
300 (5 minutes) so the migration happens as smoothly as possible.
11+
- If the migration is a planned move,
12+
it's recommended to lower the Time To Live (TTL) of your DNS records to a value such as 300 (5 minutes),
13+
at best much earlier than the actual planned migration.
14+
This speeds up propagation of DNS changes in the Internet after the migration is complete.
1515

16-
During the guide you might get a warning about changed SSH Host keys; in
17-
this case, just run ``ssh-keygen -R "mail.example.org"`` as recommended.
16+
- The migration steps were tested with a Linux laptop; you might need to adjust some of the steps to your local environment.
1817

19-
1. First, disable mail services on the old site.
18+
- Your ``mail_domain`` is ``mail.example.org``.
2019

21-
::
20+
- All remote machines run Debian 12.
21+
22+
- The old site’s IP version 4 address is ``$OLD_IP4``.
23+
24+
- The new site’s IP addresses are ``$NEW_IP4`` and ``$NEW_IPV6``.
25+
26+
27+
The six steps to migrate
28+
------------------------
2229

23-
cmdeploy run --disable-mail --ssh-host 13.37.13.37
30+
Note that during some of the following steps you might get a warning about changed SSH Host keys;
31+
in this case, just run ``ssh-keygen -R "mail.example.org"`` as recommended.
2432

25-
Now your users will notice the migration and will not be able to send
26-
or receive messages until the migration is completed.
2733

28-
2. Now we want to copy ``/home/vmail``, ``/var/lib/acme``,
29-
``/etc/dkimkeys``, and ``/var/spool/postfix`` to
30-
the new site. Login to the old site while forwarding your SSH agent
31-
so you can copy directly from the old to the new site with your SSH
32-
key:
34+
1. **Initially transfer mailboxes from old to new site.**
3335

36+
Login to old site, forwarding your ssh-agent with ``ssh -A``
37+
to allow using ssh to directly copy files from old to new site.
3438
::
3539

36-
ssh -A root@13.37.13.37
37-
tar c - /home/vmail/mail /var/lib/acme /etc/dkimkeys /var/spool/postfix | ssh root@13.12.23.42 "tar x -C /"
40+
ssh -A root@$OLD_IP4
41+
tar c /home/vmail/mail | ssh root@$NEW_IP4 "tar x -C /"
3842

39-
This transfers all addresses, the TLS certificate,
40-
and DKIM keys (so DKIM DNS record remains valid).
41-
It also preserves the Postfix mail spool so any messages
42-
pending delivery will still be delivered.
4343

44-
3. Install chatmail on the new machine:
44+
2. **Pre-configure the new site but keep it inactive until step 6**
45+
::
46+
47+
CMDEPLOY_STAGES=install,configure scripts/cmdeploy run --ssh-host $NEW_IP4
48+
49+
50+
3. **It's getting serious: disable mail services on the old site.**
51+
Users will not be able to send or receive messages until all steps are completed.
52+
Other relays and mail servers will retry delivering messages from time to time,
53+
so nothing is lost for users.
4554

4655
::
4756

48-
cmdeploy run --disable-mail --ssh-host 13.12.23.42
57+
scripts/cmdeploy run --disable-mail --ssh-host $OLD_IP4
58+
4959

50-
Postfix and Dovecot are disabled for now; we will enable them later.
51-
We first need to make the new site fully operational.
60+
4. **Final synchronization of TLS/DKIM secrets, mail queues and mailboxes.**
61+
Again we use ssh-agent forwarding (``-A``) to allow transfering all important data directly
62+
from the old to the new site.
63+
::
64+
65+
ssh -A root@$OLD_IP4
66+
tar c /var/lib/acme /etc/dkimkeys /var/spool/postfix | ssh root@$NEW_IP4 "tar x -C /"
67+
rsync -azH /home/vmail/mail root@$NEW_IP4:/home/vmail/
5268

53-
4. On the new site, run the following to ensure the ownership is correct
54-
in case UIDs/GIDs changed:
69+
Login to the new site and ensure file ownerships are correctly set:
5570

5671
::
5772

73+
ssh root@$NEW_IP4
5874
chown root: -R /var/lib/acme
5975
chown opendkim: -R /etc/dkimkeys
6076
chown vmail: -R /home/vmail/mail
6177

62-
5. Now, update DNS entries.
6378

64-
If other MTAs try to deliver messages to your chatmail domain they
65-
may fail intermittently, as DNS catches up with the new site settings
66-
but normally will retry delivering messages for at least a week, so
67-
messages will not be lost.
79+
5. **Update the DNS entries to point to the new site.**
80+
You only need to change the ``A`` and ``AAAA`` records, for example:
81+
82+
::
83+
84+
mail.example.org. IN A $NEW_IP4
85+
mail.example.org. IN AAAA $NEW_IP6
86+
87+
88+
6. **Activate chatmail relay on new site.**
89+
90+
::
91+
92+
CMDEPLOY_STAGES=activate scripts/cmdeploy run --ssh-host $NEW_IP4
6893

69-
6. Finally, you can execute ``cmdeploy run --ssh-host 13.12.23.42`` to
70-
turn on chatmail on the new relay. Your users will be able to use the
71-
chatmail relay as soon as the DNS changes have propagated. Voilà!
94+
Voilà!
95+
Users will be able to use the relay as soon as the DNS changes have propagated.
96+
If you have lowered the Time-to-Live for DNS records in step 1,
97+
better use a higher value again (between 14400 and 86400 seconds) once you are sure everything works.
7298

0 commit comments

Comments
 (0)