Getting rsync right from the start saves hours of debugging later. In this comprehensive guide, we'll cover everything from initial setup to production-ready configuration, including minimal-downtime and migration considerations.
Prerequisites
- Sufficient storage on the destination server
- A VPS running Ubuntu 22.04 or later (2GB+ RAM recommended)
- Basic familiarity with the Linux command line
- Access to both source and destination servers
Pre-Migration Assessment
The default configuration works well for development environments, but production servers require additional tuning. Pay particular attention to connection limits, timeout values, and logging settings.
# Pre-migration data sync with rsync
rsync -avzP --delete \
--exclude='/dev' --exclude='/proc' --exclude='/sys' --exclude='/tmp' \
-e 'ssh -p 22' \
root@old-server:/ /mnt/migration/
# Final sync with minimal downtime
rsync -avzP --delete \
-e 'ssh -p 22' \
root@old-server:/var/www/ /var/www/
These commands should be run as root or with sudo privileges. If you're using a non-root user, prefix each command with sudo.
Data Transfer Process
Before making changes to the configuration, always create a backup of the existing files. This ensures you can quickly roll back if something goes wrong during the setup process.
Important Notes
Performance benchmarks show that properly tuned rsync can handle significantly more concurrent connections than the default configuration. The key improvements come from adjusting worker processes and connection pooling.
Configuration Migration
After applying these changes, monitor the server's resource usage for at least 24 hours to ensure stability. Tools like htop, iostat, and vmstat can provide real-time insights into system performance.
DNS Cutover Procedure
After applying these changes, monitor the server's resource usage for at least 24 hours to ensure stability. Tools like htop, iostat, and vmstat can provide real-time insights into system performance.
# Database migration
# On source server:
mysqldump --single-transaction --routines --triggers --all-databases | gzip > db_backup.sql.gz
# Transfer to destination:
scp db_backup.sql.gz root@new-server:/tmp/
# On destination server:
gunzip < /tmp/db_backup.sql.gz | mysql -u root
This configuration provides a good balance between performance and resource usage. For high-traffic scenarios, you may need to increase the limits further.
Common Issues and Solutions
- High memory usage: Review the configuration for memory-related settings. Reduce worker counts or buffer sizes if running on a low-RAM VPS.
- Connection timeout: Verify your firewall rules allow traffic on the required ports. Use
ss -tlnpto confirm the service is listening on the expected port. - Service won't start: Check the logs with
journalctl -xe -u rsync. Common causes include port conflicts, missing configuration files, or insufficient permissions.
Next Steps
With rsync now set up and running, consider implementing monitoring to track performance metrics over time. Regularly review your configuration as your workload changes and scale resources accordingly.