How to Install and Use rsync for Backups
Introduction
rsync is a powerful and efficient tool for backing up and synchronizing files and directories in Linux. This guide shows you how to install rsync and use it for local and remote backups.
Step-by-step Guide
- Install rsync
- sudo apt update
- sudo apt install rsync
- Basic local backup with rsync
- rsync -avh /source/directory/ /destination/directory/n
- (Replace
/source/directory/and/destination/directory/with your actual paths)
- (Replace
- rsync -avh /source/directory/ /destination/directory/n
- Backup to a remote server via SSH
- rsync -avh -e ssh /source/directory/ user@remote_ip:/remote/backup/directory/n
- (Replace
user,remote_ip, and paths as needed)
- (Replace
- rsync -avh -e ssh /source/directory/ user@remote_ip:/remote/backup/directory/n
- Restore files from backup
- rsync -avh user@remote_ip:/remote/backup/directory/ /restore/location/
- (Optional) Exclude files or directories from backup
- rsync -avh --exclude 'node_modules' /source/ user@remote_ip:/remote/backup/
- (Optional) Run rsync as a cron job for automatic backups
- Edit your crontab:n
- crontab -e
- Add a line like:n
- 0 3 * * * rsync -avh /source/ /destination/
- Edit your crontab:n
Recommendations
- Always test your backup and restore process before relying on it.
- Use SSH keys for secure, passwordless remote backups.
- Regularly monitor your backup logs for errors.
Call To Action
Looking for reliable storage for your backups? Try our VPS plans! https://xernode.com/#pricing