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.

Loading

Full text search

Recent Posts

  • Error 0xc1900101 when updating to Windows 11 22H2
  • Apply changes to all member accounts in an AWS organization
  • RPI4 under voltage
  • Upgrade RockyLinux 8 to 9
  • Terraform and segregated permissions
  • aws (9)
  • coffee (1)
  • headfi (1)
  • linux (8)
  • others (57)
  • security (2)
  • tech (39)
  • wordpress (2)

Loading

apache apigateway aws awscli azure backup cloud coffee docker ec2 EL8 ElasticBeanstalk enpass espresso featured kernel lelit linux lvm meltdown MFA mikrotik nat gateway nginx php power python rdp Redhat RHEL rpm Ryzen s2s scp serverless site-to-site snapshot spectre tech terraform ubuntu ubuntu upgrade vpn wordpress xdotool

©2023 blog.headdesk.me | Powered by SuperbThemes