Rsync backups and Btrfs
For years I’m doing backups using rsync. Especially the variant using hardlinks, in order to get backups that only consume the disk space needed by an incremental backup, but being being able to access each daily backup as if it was a full one. The whole call looks like rsync -a --delete $OTHER_OPTIONS --link-dest=27/ $SRC/ 28/
(for the 28th of the month). Prior to doing each backup, I’m removing the backup from the previous month - a bit unsure why I exactly do this, the –delete option of rsync should exactly do the job)
Some time ago, I’ve replaced the drive used for backup by a new one, and in this context I’ve switched from ext4 to btrfs, in order to take advantage of its data protection features (btrfs scrub
)
While this should not be an issue at all, I’ve noticed that the whole process is taking ages. Example from today :
|
|
So… 2h for removing xxx files, followed by 2h for the backup (OK, maybe today there were a bit more files than usual to backup)
Google is your friend… btrfs has terrific performance when it comes to deleting hundred thousands of files :-( In combination with rsync, the prefered solution seems to be using btrfs snapshots, which can be deleted a light speed. Some references :
- https://www.sanitarium.net/golug/rsync+btrfs_backups_2011.html
- https://www.funtoo.org/BTRFS_Fun
- https://github.com/oxplot/rsyncbtrfs/blob/master/rsyncbtrfs
The last one, rsyncbtrfs, is a quite complete all-in-one scripted solution that combines creating a subvolume, performing the sync and creating a snapshot. It also includes a few safeguards in case problems arise.
In the end I’ve adapted my scripts with some inspiration from the rsyncbtrfs script :
|
|
Update: here the backup time with the snapshot system
|
|