Backup Strategies for Linux: rsync, tar, and Scheduling
Implement Linux backups with rsync for incremental sync, tar for archives, and cron for scheduling. Covers local, remote, and offsite backup strategies.
A backup you have never tested is not a backup — it is wishful thinking. Data loss happens through hardware failure, accidental deletion, ransomware, and misconfigured commands, and it is rarely predictable. The most widely recommended backup strategy is the 3-2-1 rule: keep at least 3 copies of your data, on 2 different types of media, with 1 copy stored offsite (or in a separate cloud region). Linux provides powerful command-line tools to implement this strategy without expensive proprietary software.
rsync is the workhorse of Linux backups. It transfers only the files that have changed since the last run, making it extremely efficient for large directory trees.
Local backups
Remote backups
# Basic syncrsync -avz /source/ /backup/# Delete files not in source (mirror)rsync -avz --delete /source/ /backup/# Exclude patternsrsync -avz --exclude='*.log' --exclude='tmp/' /source/ /backup/# Dry run (test without changes)rsync -avzn /source/ /backup/# With progressrsync -avz --progress /source/ /backup/
# Remote backup over SSHrsync -avz /source/ user@backup-server:/backup/
rsync uses SSH for remote transfers by default. Make sure you have SSH key authentication configured so automated cron jobs can run without a password prompt.
The trailing slash on the source path matters. rsync -av /source/ /backup/ copies the contents of /source into /backup. Without the trailing slash, rsync -av /source /backup/ creates a /backup/source/ subdirectory. Always double-check your paths, especially when using --delete.
The $(date +%Y%m%d) substitution automatically names the archive with today’s date (e.g., backup-20240315.tar.gz), making it simple to manage multiple dated backups in the same directory.
Automate your backup jobs by adding entries to your crontab. The format is minute hour day month weekday command.
crontab -e # edit user crontab
Add entries like these to your crontab:
# Daily backup at 2am0 2 * * * rsync -az /home/ /backup/home/# Weekly full backup on Sunday at 3am0 3 * * 0 tar -czf /backup/weekly-$(date +\%Y\%m\%d).tar.gz /home# Monthly cleanup - remove backups older than 30 days0 4 1 * * find /backup/ -name "*.tar.gz" -mtime +30 -delete
Percent signs (%) have special meaning in crontab and must be escaped as \%. Redirect output to a log file to capture errors: append >> /var/log/backup.log 2>&1 to each entry.
Restic encrypts all data at rest and uses content-addressed deduplication, meaning it never stores the same block of data twice even across different snapshots.
Test your restores regularly — on a schedule, not just when disaster strikes. Restore a random file from last week’s backup, verify the database dump loads cleanly into a test instance, or do a full restore to a spare machine once a quarter. A backup you have never successfully restored from is unreliable by definition.