Using Rsync for Large-Scale Server Migrations (Hands-on Guide)

Using Rsync for Large-Scale Server Migrations (Hands-on Guide)
Photo by Ingmar H / Unsplash

πŸš€

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


Read more