Paj Digital Labs
All articles
Hosting & Server Infrastructure

Zero-Downtime Site Migrations: The Rehearsal, the Cutover, the Rollback

Migrations fail at the boring parts — TTL, sticky sessions, mail records and the write that lands on the old box after cutover. The runbook we actually use.

Paj Digital Labs 5 min read
Server racks and network cabling in a data center
Editorial illustration · Hosting & Server Infrastructure

A migration is not a copy operation. Copying files is fifteen minutes of rsync. The risk lives in the window where two servers both believe they are authoritative, and in the records nobody remembered were pointed at the old IP.

We have moved several hundred sites between hosts. The ones that went badly all failed in the same four places.

Step 0 — Inventory, before you touch anything

Write it down. Anything not on this list will be the thing that breaks.

  • DNS zone: every record, not just A and www. Mail, subdomains, verification TXT records, CDN CNAMEs.
  • Cron jobs, including anything an external scheduler hits by IP.
  • Scheduled tasks inside the application (WP-Cron, Laravel scheduler).
  • Outbound mail path: local sendmail, SMTP relay credentials, SPF entries containing the old IP.
  • TLS: who issues the certificate, and does issuance require the domain to already resolve to the new host?
  • Anything hardcoding an absolute path or IP — payment gateway IP allowlists are the classic.
bash
class="text-code-comment"># Dump the current zone from the authoritative nameserver, not your resolver
dig +noall +answer +authority ANY example.com @ns1.currenthost.com
crontab -l -u www-data > /tmp/migration/crontab-www-data.txt
grep -rn class="text-code-string">"$(dig +short A example.com)" /etc /home/app --include=class="text-code-string">'*.conf' --include=class="text-code-string">'*.env'

Step 1 — Lower the TTL a full day early

This is the single cheapest thing you can do, and skipping it is why "the site is still on the old server" tickets exist.

text
example.com.      300   IN  A   203.0.113.10
www.example.com.  300   IN  A   203.0.113.10

Drop to 300 seconds at least 24 hours before cutover — resolvers have to expire the old TTL before they see the new one. Verify it actually took:

bash
dig +noall +answer example.com @1.1.1.1 | awk class="text-code-string">'{print $2, "seconds TTL"}'

Raise it back to 3600 or higher a day after the migration settles. Leaving 300 forever means every visitor pays extra DNS lookups.

Step 2 — Rehearse on the new box with a hosts override

Bring the new server fully up — same PHP version, same extensions, same TLS config — and test it before any public DNS change, by lying to your own machine.

text
class="text-code-comment"># /etc/hosts on your laptop
198.51.100.20  example.com www.example.com

Now walk the real journeys, not the homepage: log in, add to cart, complete a test checkout, submit the contact form, upload a file to the media library, load an admin page that hits every plugin. Check the new server's error log while you do it. Then remove the hosts entry.

Rehearsal is also when you catch the missing PHP extension, the wrong upload_max_filesize, and the cron user that does not exist yet.

Step 3 — The two-phase data sync

The mistake is a single copy during the maintenance window. Do a bulk pass while the old site is still live, then a short delta pass at cutover.

bash
class="text-code-comment"># Phase A — days before. Slow, safe, repeatable.
rsync -aHAX --numeric-ids --info=progress2 \
  --exclude=class="text-code-string">'wp-content/cache/' --exclude=class="text-code-string">'*.log' \
  root@old:/var/www/example/ /var/www/example/
class="text-code-comment">
# Phase B — during the window, after writes are stopped. Minutes, not hours.
rsync -aHAX --delete --numeric-ids \
  root@old:/var/www/example/ /var/www/example/

The database is the part that cannot be eventually consistent. For anything transactional, put the old site into read-only or maintenance mode for the dump:

bash
class="text-code-comment"># On old host — single-transaction avoids locking InnoDB tables
mysqldump --single-transaction --quick --routines --triggers \
  --default-character-set=utf8mb4 appdb | zstd -3 > /tmp/appdb.sql.zst

scp /tmp/appdb.sql.zst new:/tmp/
ssh new class="text-code-string">'zstd -dc /tmp/appdb.sql.zst | mysql appdb'

For a site with meaningful write volume, set up replication from old to new instead, and cut over by promoting the replica. That turns a thirty-minute window into a thirty-second one.

Step 4 — Cutover, in order

1. Enable maintenance mode on the old host. This is what makes the migration safe: no write can land on a box you are about to abandon. 2. Run the delta rsync and the final database import. 3. Smoke-test the new host again through /etc/hosts. 4. Change the DNS A records. 5. Leave the old host serving maintenance mode — do not shut it down.

That last point matters. Stale resolvers and hardcoded IPs will keep hitting the old address for hours. A maintenance page there is a mild annoyance; a connection refused is a broken site, and a still-writable old application is silent data loss.

Step 5 — Verify from outside your network

Your resolver caches. Your browser caches harder.

bash
for r in 1.1.1.1 8.8.8.8 9.9.9.9 208.67.222.222; do
  printf class="text-code-string">'%-16s %s\n' class="text-code-string">"$r" class="text-code-string">"$(dig +short A example.com @$r)"
done

curl -sSI https://example.com | head -1
curl -s https://example.com/health | jq .
echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null \
  | openssl x509 -noout -dates -subject

Then check mail actually flows — send one real message and read the receiving headers. SPF that still lists the old IP will pass for a while and start failing the day you decommission the box.

The rollback plan you write before you start

If it is not written down before the window opens, you do not have one.

| Failure | Detection | Action | | :--- | :--- | :--- | | New host errors after cutover | 5xx rate, error log | Point DNS back to the old IP; old host is still warm | | Data written to the new host is wrong | Application checks, order counts | Restore the pre-cutover dump; the old host was read-only, so nothing was lost | | TLS not issuing on the new host | openssl s_client fails | Serve the old certificate you copied during rehearsal | | Mail bouncing | Bounce messages, delivery log | Re-point the MX record; keep the old mail server running |

Rollback is only cheap because you kept the old host up and read-only. That is the entire trick. Everything else on this page is a checklist; that one decision is the design.

Decommission on a delay

Keep the old server running, in maintenance mode, for seven days minimum. Take a final full snapshot before you destroy it, and keep that snapshot for a month. The bill is a few dollars. The alternative is discovering on day nine that an obscure reporting cron only ever existed on the old box.

Paj Digital Labs

The engineering journal of Paj Digital Solutions — hosting, server infrastructure and web engineering, written by the people who run the servers.

Related reading