Copying data between servers with rsync
rsync compares both sides and sends only the difference, which makes it the right tool for moving terabytes between machines and keeping them in step afterwards.
What is the basic command?
Run rsync on either machine with archive mode, which keeps permissions, owners, timestamps and symlinks. Pushing from the old server to the new one looks like this:
rsync -aHAX --numeric-ids --info=progress2 /srv/www/ root@203.0.113.60:/srv/www/
The flags matter. -H keeps hard links, -A and -X keep ACLs and extended attributes (needed for SELinux labels and some applications), and --numeric-ids maps owners by number instead of name, so files land with the right owner even before matching users exist on the target. --info=progress2 shows one overall progress line rather than a line per file.
Why does the trailing slash matter?
A trailing slash on the source copies the contents of the folder; leaving it off copies the folder itself. /srv/www/ into /srv/www/ gives the same layout on both sides, while /srv/www into /srv/www/ creates /srv/www/www. Do a dry run with -n when unsure; it lists what would change without writing anything.
rsync -aHAXn --numeric-ids --itemize-changes /srv/www/ root@203.0.113.60:/srv/www/ | head
How do I let the two servers talk?
With an SSH key that the source can use to log in to the target. Generate a dedicated key on the source, add its public half to the target's authorized_keys, and restrict it if the key will stay around after the move. The rsync package ships a helper, rrsync, that confines a key to one directory.
ssh-keygen -t ed25519 -f ~/.ssh/move_key -N "" -C "move-to-new" ssh-copy-id -i ~/.ssh/move_key.pub root@203.0.113.60 rsync -aHAX -e "ssh -i ~/.ssh/move_key" /srv/www/ root@203.0.113.60:/srv/www/
Remove the key from the target when the migration is over. Because there is no private network between machines here, all of this traffic crosses the public port, and SSH encrypts it on the way.
How fast will the copy run?
Close to the slower port when there are big files, and slower with millions of small ones. Between two machines in the same region on 1 Gbps ports, expect about 100 MB per second, roughly 350 GB an hour. Business machines with a 3 Gbps port and Storage machines with 10 Gbps move more if both ends match. For small files the limit is per-file overhead, not bandwidth; running several rsync processes in parallel, one per top-level folder, helps a lot.
ls /srv/data | xargs -P 4 -I{} rsync -aHAX --numeric-ids /srv/data/{} root@203.0.113.60:/srv/data/
Can I resume a copy that stopped?
Just run the same command again: rsync skips what already matches. For very large single files, add --partial so an interrupted file is kept and continued rather than restarted, and --append-verify if you are sure the source file only grows. Run long copies inside tmux or screen so a dropped laptop connection does not end them.
Should I compress the transfer?
Usually not between servers. Compression with -z costs CPU on both ends and only pays off on slow links with compressible data such as logs or SQL dumps. Media, archives and database files that are already compressed gain nothing. On a fast port, a lighter SSH cipher such as aes128-gcm@openssh.com helps more on older processors.
| Option | Use it when |
|---|---|
--delete | The target must become an exact mirror, removing files deleted on the source |
--bwlimit=40M | The source still serves users and needs bandwidth left |
--exclude-from=list.txt | Caches, temporary files or sockets should stay behind |
--checksum | Timestamps cannot be trusted; slower, reads every file |
--partial | Large single files on an unstable link |
How do I copy a live database or application safely?
Do a bulk copy while it runs, then stop it and do a short final pass. The first pass moves almost all of the data, and the second only the files that changed since, which usually takes seconds to minutes. Databases need extra care: a copy of the data directory taken while the database writes is not consistent. Either stop the database for the final pass, or use the database's own dump or replication instead, as described in Migrate to a new server.
rsync -aHAX --numeric-ids --delete /srv/app/ root@203.0.113.60:/srv/app/ # pass 1, live systemctl stop app.service rsync -aHAX --numeric-ids --delete /srv/app/ root@203.0.113.60:/srv/app/ # pass 2, short
How do I check the copy is complete?
Run a final dry run with --checksum; if it lists nothing, both sides match byte for byte. For a quick sanity check, compare file counts and total size with du -s --apparent-size and find | wc -l on both sides. For data that you keep mirrored long term, a nightly rsync to a machine in another location, such as a Storage server in Strasbourg for a primary in Gravelines, is a simple and dependable backup.
Related pages
Migrate to a new server
Move a live service to a newer or larger machine with minutes of downtime: plan the overlap, copy, replicate the database and switch DNS.
Read moreTransfer files with SFTP
Upload and download files over SSH with sftp, scp or a graphical client, and give outside users a locked upload folder.
Read moreBackup and archive storage
Hard disk chassis from 44 TB to 576 TB raw for offsite backups, archives and object storage targets.
Read moreQuestions and answers
Which rsync flags preserve everything?
Use -aHAX with --numeric-ids. That keeps permissions, owners, times, symlinks, hard links, ACLs and extended attributes.
Is the transfer encrypted?
Yes. rsync over SSH encrypts everything in transit, which matters because traffic between servers crosses the public port.
Can I resume an interrupted rsync?
Run the same command again. Add --partial so large files that were cut off are continued rather than restarted.
Should I use -z compression between servers?
Rarely. On fast links and already compressed data it only costs CPU. Use it for slow links with logs or text dumps.
Can rsync copy a running database?
Not consistently. Stop the database for the final pass, or use its own dump or replication tools.