1

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

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

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

  • Create a subvolume for the each folder that is to be excluded. (Con: automatically generated folders can not be excluded as they are created as regular folders, such as node_modules in this scenario)
  • Create a temporary subvolume, delete the unwanted files/folders (Most promising approach), then create the final subvolume from it.

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

1 Answer 1

2

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

3
  • ...because excluding directories would break the atomicity nature of snapshotting, right?
    – ceremcem
    Commented Aug 18, 2018 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/… Commented Aug 18, 2018 at 12:41
  • Until its implemented, this should be the accepted answer then.
    – ceremcem
    Commented Aug 20, 2018 at 20:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .