Cloud VPS from $1.98/mo · pay with Bitcoin, Ethereum, Monero, USDT or Solana · paid in crypto
DevOps

Server migration toolkit: move files, databases and DNS

Move a Linux server to a new VPS with open-source tools: rsync for files, native dumps or replication for databases, curl to test, and dig for the DNS switch.

CloudSat teamNovember 18, 20268 min read
Abstract illustration of glowing parcels traveling along a bright arc between two server silhouettes on a dark grid
On this pageThe toolkit at a glance

Migration suites built for hundreds of virtual machines are overkill when you are moving one Linux server, or five, to a new VPS. The job needs a short list of tools you probably have already, used in the right order: take stock, copy files, move the databases, test, switch DNS, verify. Each section below covers one of those jobs and the flags that matter. For deciding what moves and when, see how to plan a cloud migration. The examples use 198.51.100.20 for the old server and 203.0.113.10 for the new one.

The toolkit at a glance

Job Tool Runs on
List what runs ss, systemctl, crontab Old server
Copy files rsync over SSH Old server, pushing
Copy buckets and remote storage rclone Either side
Move PostgreSQL pg_dump, pg_restore, logical replication Both
Move MySQL or MariaDB mysqldump or mariadb-dump Both
Move Docker volumes tar in a throwaway container Both
Test before the switch curl --resolve Your workstation
Switch and check DNS dig Your workstation

Take stock of the old server

Before copying anything, record what the machine actually does. Listening sockets show the services that matter, timers and crontabs show the jobs nobody remembers, and the package list shows what the new server will need.

ss -tulpn
systemctl list-units --type=service --state=running
systemctl list-timers --all
for u in $(cut -d: -f1 /etc/passwd); do crontab -l -u "$u" 2>/dev/null | sed "s/^/$u: /"; done
ls /etc/cron.d /etc/cron.daily
apt-mark showmanual > packages.txt
docker ps --format 'table {{.Names}}\t{{.Image}}\t{{.Ports}}'
du -sh /var/www /srv /home /var/lib/docker/volumes 2>/dev/null

On the RHEL family, dnf repoquery --userinstalled replaces apt-mark showmanual. Treat the package list as a checklist, not a script: names change between releases, and a fresh install is the moment to drop what you no longer use. Save the firewall rules too (nft list ruleset or ufw status verbose), because they never move by accident.

Copy files with rsync, in two passes

The first pass runs while the old server is live and moves the bulk of the data. The second pass runs during the write freeze and only transfers what changed, which is why it is short. Push from the old server as root so ownership and permissions survive:

rsync -aHAX --info=progress2 /var/www/ root@203.0.113.10:/var/www/
rsync -aHAX /etc/letsencrypt/ root@203.0.113.10:/etc/letsencrypt/

What the flags do:

  • -a recurses and keeps permissions, timestamps, owners and symlinks.
  • -H, -A and -X add hard links, ACLs and extended attributes. Drop the last two if the old server does not use them.
  • --info=progress2 prints one overall progress line instead of one line per file.
  • The trailing slash on the source copies the contents of /var/www into the target directory, instead of creating /var/www/www.

Create the service users on the new server first. With root on both ends, rsync matches owners by user and group name, so files land with the right owner even when the numeric IDs differ. Copying /etc/letsencrypt with its symlinks intact means HTTPS works the moment DNS moves, and certbot installed on the new machine keeps renewing from there.

For the final pass, preview with a dry run (-n, with -i to itemize changes), then add --delete so files removed on the old side also disappear on the new one:

rsync -aHAXn -i --delete /var/www/ root@203.0.113.10:/var/www/
rsync -aHAX --delete --info=progress2 /var/www/ root@203.0.113.10:/var/www/

Copy data, not the operating system

Resist copying / wholesale. /proc, /sys and /dev are virtual, and files such as /etc/fstab, the network configuration and the boot loader describe the old machine's disks and interfaces. Copy application directories, data and the configuration files you have reviewed, then install packages on the new server from its own repositories.

Move buckets and remote storage with rclone

Media libraries in object storage, or files on an SFTP host, move best with rclone. Define both ends once with rclone config, then copy and compare:

rclone copy old:media new:media --transfers 16 -P
rclone check old:media new:media

rclone copy never deletes anything at the destination. rclone sync does, so save it for a final pass when the target should mirror the source exactly. rclone check reports files that differ or exist on only one side, without changing either.

Move the databases

Copying the data directory of a running database gives you an inconsistent copy. Use each engine's own tools: a dump for small and medium databases, replication when the dump takes longer than your downtime window.

PostgreSQL

Dump the roles once, then each database in the custom format, which pg_restore can load with several parallel jobs:

sudo -u postgres pg_dumpall --globals-only > globals.sql
sudo -u postgres pg_dump -Fc -f /tmp/appdb.dump appdb
rsync -a globals.sql /tmp/appdb.dump root@203.0.113.10:/tmp/

On the new server, load the roles, create the empty database and restore it with four jobs. An error saying that the postgres role already exists is expected.

sudo -u postgres psql -f /tmp/globals.sql
sudo -u postgres createdb -O appuser appdb
sudo -u postgres pg_restore -j 4 -d appdb /tmp/appdb.dump

Parallel restore needs a regular file in the custom or directory format; it cannot read from a pipe.

MySQL and MariaDB

--single-transaction takes a consistent snapshot of InnoDB tables without locking the application out, and --routines and --events add stored procedures and scheduled events. Triggers are included by default.

mariadb-dump --single-transaction --routines --events --databases appdb > appdb.sql
mariadb < appdb.sql

On MySQL, the same flags work with mysqldump and mysql. Recent MariaDB releases print a deprecation warning for the old mysql names, so use the mariadb ones there. Recreate application users on the new server with CREATE USER and GRANT instead of copying the system tables between versions; SHOW GRANTS on the old server lists what each user needs.

MongoDB, Redis and Valkey

mongodump --db=appdb --archive=appdb.archive --gzip and mongorestore --archive=appdb.archive --gzip move a MongoDB database as one file. For Redis or Valkey, point the new instance at the old one with REPLICAOF 198.51.100.20 6379 (set masterauth if the old one uses a password), wait for the sync to complete, and promote it with REPLICAOF NO ONE at cutover.

When a dump is too slow, replicate

If a dump and restore takes longer than the downtime you can accept, keep a live copy instead. PostgreSQL logical replication streams row changes from the old server to the new one, even across major versions:

-- old server, after setting wal_level = logical and restarting
CREATE PUBLICATION move_all FOR ALL TABLES;

-- new server, after loading the schema with pg_dump --schema-only
CREATE SUBSCRIPTION move_all
  CONNECTION 'host=198.51.100.20 dbname=appdb user=replicator password=change-me'
  PUBLICATION move_all;

The subscription copies the existing rows, then streams changes. It does not carry schema changes or sequence values, so avoid schema changes during the move, set each sequence with setval() at cutover, then run DROP SUBSCRIPTION. The replicator role needs the REPLICATION attribute and read access to the tables, and the old server's pg_hba.conf and firewall should admit only the new server's address. MySQL and MariaDB follow the same pattern with their native replication.

Move Docker volumes

Stop the stack, then archive each named volume through a throwaway container. Compose prefixes volume names with the project name, so take the exact names from docker volume ls on each side:

docker compose stop
docker run --rm -v app_data:/data -v "$PWD":/backup alpine tar czf /backup/app_data.tgz -C /data .
rsync -a app_data.tgz compose.yaml root@203.0.113.10:/opt/app/

On the new server, let Compose create the containers and volumes without starting them, unpack the archive into the volume, then start the stack:

cd /opt/app
docker compose up --no-start
docker run --rm -v app_data:/data -v "$PWD":/backup alpine tar xzf /backup/app_data.tgz -C /data
docker compose up -d

Test the new server before DNS changes

Your workstation can reach the new server under the real hostname before anyone else does. curl --resolve pins the name to the new address for one request, so TLS and virtual hosts behave exactly as they will after the switch:

curl -sI --resolve example.com:443:203.0.113.10 https://example.com/

For a browser session, add 203.0.113.10 example.com to your local hosts file, run the smoke tests, and remove the line afterwards. If the new server is a CloudSat VPS, take a snapshot once these tests pass and before the final sync, so a failed attempt can restart from a known-good state.

Switch DNS and confirm it

Lower the TTL of the records you will change at least one old TTL ahead. On the day, update the records, then ask the authoritative name server directly instead of a resolver that may still hold the old answer:

dig +short NS example.com
dig +short example.com A @ns1.example.net

Verify, then decommission

Right after the final sync, a checksum dry run confirms the copy. It compares file contents rather than sizes and dates, and should list nothing:

rsync -aHAXn -i --checksum --delete /var/www/ root@203.0.113.10:/var/www/

Then keep the old server running, read-only, for a few days. Its access logs reveal clients that still use the old address. When they go quiet, take a final archive, wipe the disks and cancel the service.

FAQ

Can I copy the whole disk image instead?

You can stream a disk with dd over SSH or convert a VM image with qemu-img, but the copy brings the old kernel, drivers, partition layout and network configuration into a machine that may not match them. It suits moves between identical virtual platforms. Between providers, a fresh install plus copied data and reviewed configs is easier to debug when something does not start.

How do I avoid losing writes during the switch?

Freeze them before the last sync, never after: maintenance mode on, workers and cron jobs stopped, then the final rsync pass and the final dump or replication catch-up. Anything written on the old side after the freeze has to be replayed by hand.

Do I need to stop the database to dump it?

No. pg_dump produces a consistent snapshot while PostgreSQL keeps serving queries, and --single-transaction does the same for InnoDB tables in MySQL and MariaDB. You stop writes only for the final dump at cutover, so nothing changes after the copy is taken.

Run it on CloudSat. Cloud VPS on AMD EPYC and NVMe from $1.98/mo in 13 regions, delivered in under 5 minutes and paid in crypto. See plans or deploy a server.