Man, it takes such a long time to scan 5,000,000 inodes every single day to find files that changed!
What if there was a way to back up only the changes since the last backup?
Well, you can… with snapshots!
The biggest hurdle to snapshots is switching to a file system that supports them.
On Linux, two well-known snapshotting file systems are:
- Btrfs – Designed for Linux, less battle-tested
- ZFS – Ported to Linux, been around longer
Both are copy-on-write file systems. What that practically means for you is that they keep track of the changes since the last snapshot so that when you send the latest snapshot to the backup server, only the changes get sent but you still have a complete copy of all daily backups that you decide to keep.
This means that as a bonus, you have the potential of keeping more than one day of backups for not much extra space (only the disk space used by the changes each day), and you can flexibly delete the backups, keeping weekly, monthly, or yearly backups as you desire.
This is an example of commands you can run to make incremental backups and send them to your backup server:
# Make a snapshot
btrfs subvolume snapshot -r /app/data /backup/app-data-$(date "+%Y%m%dT%H%M%S%Z")
# Ensure the snapshot is saved
sync
# Find your latest snapshot, referred to as `/backup/app-data-THIS_BACKUP_TIMESTAMP` below
ls -lhtr /backup/
# Send the snapshot since the previous snapshot to the backup server
btrfs send -p /backup/app-data-LAST_BACKUP_TIMESTAMP /backup/app-data-THIS_BACKUP_TIMESTAMP | ssh BACKUP_USER@BACKUP_SERVER "btrfs receive /backup/app-data"
Note: Exclude -p /backup/app-data-LAST_BACKUP_TIMESTAMP from the last command if this is the first backup.
This is an example of commands you can run to make incremental backups and send them to your backup server:
# Create a snapshot of the "data" dataset in your "app-pool" zpool
zfs snapshot app-pool/data@$(date "+%Y%m%dT%H%M%S%Z")
# Find your latest snapshot, referred to as `app-pool/data@THIS_BACKUP_TIMESTAMP` below
zfs list -rt snapshot app-pool/data
# Send the snapshot since the previous snapshot to the backup server
zfs send -i app-pool/data@LAST_BACKUP_TIMESTAMP app-pool/data@THIS_BACKUP_TIMESTAMP | ssh BACKUP_USER@BACKUP_SERVER "zfs receive backup-pool/app-data"
Note: Exclude -i app-pool/data@LAST_BACKUP_TIMESTAMP from the last command if this is the first backup.