Quick Summary: A solid backup strategy is the last line of defense against data loss from hardware failure, ransomware, human error, or natural disasters. rsync provides fast incremental file synchronization, while Borg Backup adds deduplication, compression, and encryption for efficient, secure long-term storage. Together, they form a comprehensive Linux backup solution.
The 3-2-1 Backup Rule
Every backup strategy should follow the 3-2-1 rule:
- 3 copies of your data (original + 2 backups)
- 2 different storage media (local disk + remote/cloud)
- 1 copy offsite (different physical location)
rsync: Fast Incremental Synchronization
Essential rsync Commands
rsync -avz /source/ /backup/ā Archive mode, verbose, compressedrsync -avz --delete /source/ /backup/ā Mirror (delete files removed from source)rsync -avz -e "ssh -p 2222" /source/ user@remote:/backup/ā Remote backup via SSHrsync -avz --exclude="*.log" --exclude="cache/" /source/ /backup/ā Exclude patternsrsync --dry-run -avz /source/ /backup/ā Test without making changes
rsync Flags Explained
| Flag | Meaning |
|---|---|
-a | Archive mode (preserves permissions, timestamps, symlinks) |
-v | Verbose output |
-z | Compress data during transfer |
--delete | Remove files from destination not in source |
--progress | Show transfer progress per file |
--bwlimit=5000 | Limit bandwidth to 5MB/s |
-n | Dry run (simulate without changes) |
Borg Backup: Deduplicated, Encrypted Backups
Borg Backup is a modern backup tool that excels at space-efficient, encrypted backups:
Setting Up Borg
- Install:
sudo apt install borgbackuporsudo dnf install borgbackup - Initialize a repository:
borg init --encryption=repokey /backup/borg-repo - Create a backup:
borg create /backup/borg-repo::daily-{now} /var/www /etc /home - List archives:
borg list /backup/borg-repo - Restore files:
borg extract /backup/borg-repo::daily-2026-03-25
Borg Key Features
| Feature | Benefit |
|---|---|
| Deduplication | Only stores unique data blocks ā 10 backups of 100GB may use only 110GB |
| Compression | lz4, zstd, zlib ā reduces storage by 30-60% |
| Encryption | AES-256 ā backups are secure even on untrusted storage |
| Pruning | Automatic retention policies (keep 7 daily, 4 weekly, 12 monthly) |
| Integrity checks | borg check verifies backup consistency |
rsync vs Borg Comparison
| Feature | rsync | Borg |
|---|---|---|
| Deduplication | No (file-level only) | Yes (block-level) |
| Encryption | No (use SSH for transport) | Yes (at-rest encryption) |
| Compression | Transfer only | Storage compression |
| Versioning | Manual (hardlink rotation) | Built-in archive system |
| Speed | Very fast (incremental) | Fast (dedup overhead) |
| Complexity | Simple | Moderate |
| Best for | Simple mirrors, file sync | Long-term versioned backups |
Automating Backups
Create a backup script and schedule it with cron or systemd timers:
- Write a script that runs borg create with appropriate paths
- Add borg prune for retention policy
- Add borg check for integrity verification
- Log output with timestamps
- Schedule with cron: run daily at 2 AM
- Set up email alerts for failures
Frequently Asked Questions
How often should I back up?
Critical data: daily minimum, hourly for databases. With Borg's deduplication, daily backups of large datasets consume minimal additional storage. The cost of frequent backups is low compared to the cost of data loss.
Should I use rsync or Borg?
Use rsync for simple file synchronization between servers (mirroring). Use Borg for versioned backups with deduplication and encryption. Many setups use both: rsync for real-time replication, Borg for daily versioned backups.
How do I verify my backups work?
Regularly test restoring from backups. Run borg check for integrity verification. Schedule monthly test restores to a separate location. A backup you have never tested is not a backup ā it is a hope.