Backup and Restore with rsync
Prepare Backup drive
• Use linux file system e.g. EXT4 on the backup drive.
• Don't use FAT file system as rsync won't be able to copy all file attributes
sudo mkfs.ext /dev/sdb1 -L 'label'
Backup
sudo rsync -aAXv --delete --exclude=/dev/* --exclude=/proc/* --exclude=/sys/* --exclude=/tmp/* --exclude=/run/* --exclude=/mnt/* --exclude=/media/* --exclude="swapfile" --exclude="lost+found" --exclude=".cache" --exclude="Downloads" --exclude=".VirtualBoxVMs" --exclude=".ecryptfs" /source /destination
# -a, --archive archive mode
# -A, --acls preserve ACLs (Access Control List)
# -X, --xattrs preserve extended attributes
# -v, --verbose increase verbosity
# --delete incremental backup
# --dry-run simulate the backup
# /source use / (root) for everything
# /destination e.g. /media/user/drive
# Alternate syntax
sudo rsync -aAXv --delete --exclude={/dev/*,/proc/*,/sys/*,/tmp/*,/run/*,/mnt/*,/media/*,/home/*,/lost+found} /home /media/mainpool/backups
• For testing, remove the /boot directory from your source. The system will fail to boot
• Boot from live ISO
Mount fs and usb drive
mkdir /mnt/system /mnt/usb # mount points
lsblk # check names of devices
mount /dev/sda1 /mnt/system
mount /dev/sdb1 /mnt/usb
• Verify by checking the contents
cd /mnt/system # should have no /boot directory
ls
cd /mnt/usb
ls # should see the /boot directory
Restore
sudo rsync -aAXv --delete --exclude="lost+found" /mnt/usb/ /mnt/system
ls /mnt/system # verify
• Remove live ISO and Reboot
Schedule Backup
# Inside crontab
# m(minute) h(hour) dom(day_of_month) mon(month) dow(day_of_week) command
00 12 * * * rsync -aAX --delete --exclude '*.Trash-1000' /source/ /backup/daily
00 15 * * 5 rsync -aAX --delete --exclude '*.Trash-1000' /source/ /backup/weekly
00 16 1 * * rsync -aAX --delete --exclude '*.Trash-1000' /source/ /backup/monthly_$(date +%Y%m%d)
Index