How to Use Rsync for Zero-Downtime Server Migrations

Verified Knowledge
The Admin's Swiss Army Knife: rsync recursively synchronizes files directly from Server A to Server B over an encrypted SSH connection. It only transfers the differences between files, making it incredibly fast.
The Terrible Way to Migrate
When most beginners move a 50GB website to a new server, they use an FTP client (like FileZilla) to download the 50GB to their home computer, and then upload it to the new server.
- It takes hours.
- Connections randomly drop.
- Linux file permissions get annihilated.
Enter Rsync
rsync transfers files directly between the two servers at their maximum network pipe speed (often 1 Gbps to 10 Gbps). Better yet, if the transfer is interrupted, rsync resumes exactly where it left off.
Step 1: The Basic Transfer
Assume you are logged into your OLD Server (Source). You want to send the folder /var/www/mywebsite to your NEW Server (Destination) at IP 203.0.113.50.
Run this command on the old server:
rsync -avz /var/www/mywebsite root@203.0.113.50:/var/www/
Understanding the Flags (-avz):
-a(Archive): Preserves all permissions, symlinks, and ownerships perfectly.-v(Verbose): Shows you a scrolling list of what is currently being transferred.-z(Compress): Compresses file data during the transfer to save bandwidth.
(It will ask for the root password of the new server before beginning).
Step 2: The Two-Pass Zero Downtime Strategy
If you have a massive WooCommerce store, you can't put it in maintenance mode for 4 hours while rsync transfers 200GB of images. Here is the professional strategy:
- Pass 1 (While live): Run the
rsynccommand normally. The site stays online. It takes 4 hours, but users are still buying products on the old server. - Database Migration: Put the site in maintenance mode. Export the database and import it to the new server (Takes 2 minutes).
- Pass 2 (The Delta Transfer): Run the exact same
rsynccommand again. Because Rsync is smart, it compares the folders and only transfers the 5 new images uploaded in the last 4 hours. It finishes in 30 seconds. - Update DNS: Point your domain to the new server.
Need Free Migration Assistance?
Don't want to use Rsync? Our L3 migration experts will transfer your cPanel, WordPress, or CyberPanel sites to AmanaFlow completely free of charge.
Custom SSH Ports
If your new server has a secure, custom SSH port (e.g., 2222), you must specify it using the -e flag:
rsync -avz -e 'ssh -p 2222' /var/www/mywebsite root@203.0.113.50:/var/www/
The Trailing Slash Rule Warning
Rsync treats /folder and /folder/ wildly differently.
rsync /var/wwwwill create a new folder called "www" inside the destination.rsync /var/www/will dump the contents of "www" into the destination. Always double-check your trailing slashes!
FAQs
Q: Does rsync delete files on the destination if they were deleted on the source?
A: Not by default. If you want a perfect mirror that deletes old files on the new server, you must add the --delete flag. Use this with extreme caution.
More from Server Administration
View Category
How to Fix '502 Bad Gateway' Errors in Nginx & PHP-FPM
The most dreaded error on the internet. Learn how to debug socket connections, read Nginx error logs, and increase PHP execution limits.

Migrating from cPanel to CyberPanel: A System Admin's Guide
Why pay exorbitant cPanel license fees? Learn how to smoothly migrate your web hosting environment to the OpenLiteSpeed powered CyberPanel.

Optimizing Your MySQL my.cnf for High-Traffic WordPress
Is your database constantly crashing? Learn how to tune your InnoDB Buffer Pool, adjust max connections, and optimize MySQL for massive WordPress queries.