hunleyd / btrfs-auto-snapshot

BTRFS Automatic Snapshot Service for Linux
GNU General Public License v2.0
17 stars 4 forks source link

Reversed the check for an available BTRFS file system. #4

Closed ams-tschoening closed 2 years ago

ams-tschoening commented 2 years ago

I'm using BTRFS formatted USB disk for backup purposes, with multiple subvolumes for different purposes. btrfs-auto-snapshot is used to maintain history for each individual purpose. The default implementation doesn't support that use-case because it checks if a given path is a known mounted BTRFS file system. That is not the case, because the given path is a subvolume and that is not mounted by default, but only it's parent.

To support my use-case, the check needs to be reversed: Does the given path contain a known BTRFS file system? If so it's a subvolume most likely. In theory this could even be enhanced to check the given path against all known subvolumes for some BTRFS file system, e.g. to prevent accidently providing non-subvolume dirs or alike. Though, doesn't seem to be that important for me.

The reversed check seems to be the only thing I needed to change to support my use-case and in my opinion makes btrfs-auto-snapshot more flexible. Using different subvolumes for different purposes is pretty common with BTRFS.

bash-4.3# grep btrfs /proc/mounts | awk '{print $2}'
/volume1
/volumeUSB1/usbshare
bash-4.3#

My subvolume is in /volumeUSB1/usbshare/some_child. That is clearly not contained in the above output. Though, the second line of the above output is contained in my given path, hence the changed search for GREP. That provides everythign we need already:

-F, --fixed-strings Interpret PATTERN as a list of fixed strings, separated by newlines, any of which is to be matched. (-F is specified by POSIX .)

https://linux.die.net/man/1/grep

hunleyd commented 2 years ago

Thank you @ams-tschoening for both using my little tool and contributing back! This change makes sense to me, so I'm happy to merge it.

ams-tschoening commented 2 years ago

It's great! :-) Have deployed it to multiple Ubuntu based VMs already and am trying it right now for custom backups on Synology NAS. Simply checked out using GIT and things worked OOB. Pretty much following the concepts of zfs-auto-snapshot and not requiring additional dependencies were the perfect decisions.