Menu
blog.headdesk.me
blog.headdesk.me

Rsync backup with BTRFS

Posted on 2019/04/102019/05/15

There are plenty of backup tools in the community but I still prefer rsync for desktop backup. It only copies the changes and it does not require any catalog. I’ve been using that for years, rsync-ing my files to a USB drive. While it works fine and it saved my day a couple times, my script only keeps 1 version of backup. It’d be nice if I can have at least 2 versions, one from today and one from yesterday.

To set that up, I formatted the USB drive with BTRFS, mounted it under /backup, and created a subvolume /backup/current. Then create a read-only snapshot and put it under /backup/previous. This task is needed for tomorrow’s run.

mkfs.btrfs /dev/sdd -f
mount /dev/sdd /backup btrfs subvolume create /backup/current btrfs subvolume snapshot -r /backup/current /backup/previous rsync -a /source /backup/current/

The rsync command is a simplified version. Basically it puts a copy of my files under /backup/current. In all subsequent days, my script will perform the followings

btrfs subvolume delete /backup/previous
btrfs subvolume snapshot -r /backup/current /backup/previous
rsync -a /source /backup/current/

It first remove the snapshot for the previous day, make a new snapshot of today, and start rsync again.

To access the most recent backup, simply go into /backup/current. To access the backup for the previous day, go into /backup/previous.

With a bigger backup disk and additional script logic, this can easily be made to store more versions. Every version is immediately available for examination and restore.

To prevent accidental change of data on the backup drive, mount it before backup script runs, and unmount it after. For this particular setup, only /backup needs to be unmounted. The subvolumes will follow.

facebookShare on Facebook
TwitterTweet

Full text search

Recent Posts

  • Terraform and segregated permissions
  • LVM Compression and Deduplication
  • Edit gpg encrypted file with vim
  • Lelit Elizabeth PL92T Pressure Tuning
  • jq transformation
  • aws (8)
  • coffee (1)
  • headfi (1)
  • linux (6)
  • others (58)
  • security (2)
  • tech (36)
  • wordpress (2)

apache aws awscli azure backup clearlinux cloud coffee docker DOCP ec2 EL8 epyc espresso featured gpg jenkins kernel lelit linux lvm meltdown memory MFA mikrotik php python rdp Redhat RHEL roasting rpm Ryzen site-to-site snapshot spectre tech terraform tuning ubuntu ubuntu upgrade vim vpn wordpress xdotool

©2023 blog.headdesk.me | Powered by SuperbThemes & WordPress