0

btrfs sub snap foo bar creates an exact same contents of subvolume foo as subvolume bar, except the subvolumes in foo, which are excluded in bar.

What I want is excluding some regular folders too from the output (bar), such as node_modules and tmp; just like rsync --exclude ....

There are several ways to make this happen, for example:

  • Create a subvolume for the folders to be excluded. (Con: automatically generated folders can not be excluded as they are created regular folders, such as node_modules with this approach)
  • Create a temporary subvolume, delete unwanted files/folders (Most promising approach)

Other than above, can we apply a programmatic filter while creating snapshots?

0

No, there's no way to create a snapshot while excluding files or directories. Here's what the BTRFS wiki says:

A subvolume is like a directory - it has a name, there's nothing on it when it is created, and it can hold files and other directories. There's at least one subvolume in every Btrfs filesystem, the top-level subvolume.

As well as being like directories, subvolumes can be mounted independently of the rest of the filesystem. They are also the unit of snapshotting: you can make an atomic snapshot of a single subvolume, but not a whole tree of them; you can't make an atomic snapshot of anything smaller than a subvolume (like, say, a single directory). - https://btrfs.wiki.kernel.org/index.php/FAQ#Subvolumes

  • ...because excluding directories would break the atomicity nature of snapshotting, right? – ceremcem Aug 18 '18 at 9:16
  • 1
    I think what you're asking for could be implemented, and without breaking atomicity. It would have to be done in the BTRFS kernel module because it implements the system call used by the BTRFS tools to create snapshots. See here: git.kernel.org/pub/scm/linux/kernel/git/kdave/btrfs-progs.git/… – Emmanuel Rosa Aug 18 '18 at 12:41
  • Until its implemented, this should be the accepted answer then. – ceremcem Aug 20 '18 at 20:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.