|
1 | 1 |
|
2 | | -Migrating to a new host |
3 | | ------------------------ |
| 2 | +Migrating to a new machine |
| 3 | +=========================== |
4 | 4 |
|
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. |
8 | 7 |
|
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 | +--------------------------------- |
12 | 10 |
|
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. |
15 | 15 |
|
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. |
18 | 17 |
|
19 | | -1. First, disable mail services on the old site. |
| 18 | +- Your ``mail_domain`` is ``mail.example.org``. |
20 | 19 |
|
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 | +------------------------ |
22 | 29 |
|
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. |
24 | 32 |
|
25 | | - Now your users will notice the migration and will not be able to send |
26 | | - or receive messages until the migration is completed. |
27 | 33 |
|
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.** |
33 | 35 |
|
| 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. |
34 | 38 | :: |
35 | 39 |
|
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 /" |
38 | 42 |
|
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. |
43 | 43 |
|
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. |
45 | 54 |
|
46 | 55 | :: |
47 | 56 |
|
48 | | - cmdeploy run --disable-mail --ssh-host 13.12.23.42 |
| 57 | + scripts/cmdeploy run --disable-mail --ssh-host $OLD_IP4 |
| 58 | + |
49 | 59 |
|
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/ |
52 | 68 |
|
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: |
55 | 70 |
|
56 | 71 | :: |
57 | 72 |
|
| 73 | + ssh root@$NEW_IP4 |
58 | 74 | chown root: -R /var/lib/acme |
59 | 75 | chown opendkim: -R /etc/dkimkeys |
60 | 76 | chown vmail: -R /home/vmail/mail |
61 | 77 |
|
62 | | -5. Now, update DNS entries. |
63 | 78 |
|
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 |
68 | 93 |
|
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. |
72 | 98 |
|
0 commit comments