Using Rsync for Large-Scale Server Migrations (Hands-on Guide)
π
When migrating a large-scale Linux server, data integrity, speed, and minimal downtime are crucial. Rsync is one of the best tools for efficient server migration, as it supports incremental synchronization, compression, and SSH-based secure transfers.
π In this guide, you will learn:
β
Best practices for server migration using Rsync
β
How to perform a full server data transfer
β
How to sync only changed files to minimize downtime
β
How to migrate user accounts, permissions, and cron jobs
π 1. Key Challenges in Large-Scale Server Migrations
Migrating a large server involves transferring massive amounts of data while ensuring: πΉ Minimal Downtime β Avoiding long service disruptions.
πΉ Data Consistency β Ensuring all files, databases, and configurations remain intact.
πΉ Secure Transfers β Preventing unauthorized access during migration.
β Rsync solves these challenges by:
- Supporting incremental synchronization (
--delete
,--checksum
). - Using compression (
-z
) to reduce network traffic. - Running in background mode (
nohup
,screen
,tmux
).
β‘ 2. Planning the Rsync-Based Migration
Before running Rsync, follow these steps to ensure a smooth migration:
πΉ 2.1 Pre-Migration Checks
β
Step 1: Check Available Disk Space
Run this command on both the source and destination servers:
df -h
π Ensure that the destination server has enough space to accommodate all data.
β Step 2: Check Network Speed
iperf3 -c destination_server_ip
π A fast network (Gigabit or higher) is recommended for large-scale migrations.
β
Step 3: Create a Maintenance Window
Schedule the migration during off-peak hours to minimize disruption.
π 3. Full Server Migration with Rsync
A full migration involves copying all system files, user data, and configurations to the new server.
πΉ 3.1 Basic Full Server Rsync Command
Run the following Rsync command to transfer all system data:
rsync -avz --numeric-ids --progress --exclude={"/proc/*","/sys/*","/dev/*","/mnt/*","/tmp/*","/run/*","/lost+found"} root@source:/ root@destination:/
π Explanation of options:
-a
β Archive mode (preserves permissions, timestamps, symbolic links).-v
β Verbose mode (shows transfer progress).-z
β Compresses data to speed up transfers.--numeric-ids
β Ensures UIDs and GIDs remain consistent.--exclude
β Skips system directories (/proc
,/sys
,/dev
) that shouldnβt be copied.
β Verify the transfer:
ssh root@destination "ls -lh /"
πΉ 3.2 Using Rsync with SSH for Secure Transfers
If the new server is remote, use SSH for encrypted data transfer:
rsync -avz -e "ssh -p 2222" /source/ root@destination:/destination/
π Use a non-standard SSH port (-p 2222
) for security.
π οΈ 4. Incremental Synchronization for Faster Migration
Instead of transferring everything at once, incremental Rsync migrations allow us to:
- Perform an initial sync of most files while the old server is still running.
- Perform a final sync of only changed files right before the switchover.
πΉ 4.1 Step 1: Initial Rsync Sync
Run Rsync while the old server is live to transfer most files:
rsync -avz --exclude={"/proc/*","/sys/*","/dev/*","/tmp/*"} root@source:/ root@destination:/
π This allows 90% of the data to be transferred before downtime begins.
πΉ 4.2 Step 2: Final Rsync Sync to Minimize Downtime
Once the migration window begins, sync only changed files:
rsync -avz --delete --update /source/ root@destination:/destination/
π This reduces the final sync time to just a few minutes.
β Verify changes before cutting over:
diff -qr /source/ /destination/
π 5. Migrating Users, Permissions & Cron Jobs
After migrating files, you need to copy system configurations to ensure users, permissions, and scheduled tasks remain intact.
πΉ 5.1 Copying User Accounts
Migrate all user accounts and passwords by transferring the following files:
rsync -avz /etc/passwd /etc/group /etc/shadow /etc/gshadow root@destination:/etc/
π This ensures all users and groups are preserved.
β Verify users on the new server:
cat /etc/passwd | grep username
πΉ 5.2 Migrating SSH Keys
To allow users to log in with SSH keys, copy their ~/.ssh
directories:
rsync -avz /home/*/.ssh/ root@destination:/home/
π Ensure file permissions are correct:
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
πΉ 5.3 Transferring Cron Jobs
Copy all scheduled tasks (crontab
):
rsync -avz /var/spool/cron/ root@destination:/var/spool/cron/
β Verify crontab on the new server:
crontab -l
π 6. Testing & Verification
After migration, run these tests to confirm everything works:
β Check Disk Usage:
df -h
β Compare Source & Destination Files:
diff -qr /source/ /destination/
β Check User Accounts:
cat /etc/passwd | grep username
β
Verify Services:
Restart critical services on the new server:
sudo systemctl restart apache2
sudo systemctl restart mysql
β οΈ 7. Troubleshooting Common Migration Issues
Issue | Solution |
---|---|
Rsync Transfer is Slow | Use -z for compression, limit bandwidth with --bwlimit=1000 |
Permission Denied Errors | Run Rsync as root , check chown permissions |
Broken Symbolic Links | Use -a to preserve links, verify links with ls -lh |
Data Mismatch After Sync | Run rsync --checksum to verify file integrity |
β Debug Rsync errors by running in dry-run mode:
rsync -avz --dry-run /source/ /destination/
π 8. Summary
Migration Step | Key Action |
---|---|
Pre-Migration Check | Verify disk space, network speed, and maintenance window |
Full Data Transfer | Use rsync -avz to copy all server files |
Incremental Sync | Use rsync --update to sync only changed files |
Migrate Users & Permissions | Transfer /etc/passwd , /etc/shadow , and /etc/group |
Final Testing & Verification | Run diff -qr and restart critical services |
β Using Rsync, you can migrate large-scale Linux servers with minimal downtime and maximum efficiency.
π¬ Join the Discussion!
Have you migrated a large server using Rsync?
What challenges did you face, and how did you resolve them?
π¬ Share your experiences in the comments below! π
π Next Up: Setting Up an Rsync Daemon for Network-Wide Backups