When I tried to create a snapshot:
[root@localhost ~]# btrfs subvolume snapshot /home/admin2/ /.snapshots/s2 ERROR: Not a Btrfs subvolume: Invalid argument
How to create BTRFS snapshot for a directory?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
No simple way is known to me. I would say no, it's not possible directly.
admin2/ was a subvolume then there would be no problem. I don't think you can transparently and instantly convert a directory to a subvolume though.
There's a workaround:
Create a snapshot of the entire subvolume that holds
Remove everything but
admin2/* from the snapshot.
Rearrange data in the snapshot:
admin2/* to the top-level directory of the snapshot;
admin2/* directory, now empty) from the snapshot.
Change ownership and mode of the top-level directory of the snapshot according to the original
This way you manually create a subvolume that is what you want: a snapshot of a directory.
If you think you'll want to repeat this process in the future then consider replacing the original directory with the subvolume. Move the directory out of the way (rename or remove it), then move the subvolume into its place. Note the subvolume becomes
/home/admin2/ so you will most likely want to create yet another snapshot. But now creating a snapshot is easy, the command you tried should now work.
* Do not confuse
admin2/ in the snapshot with the original directory. Where I denote
admin2/ with asterisk I mean
admin2/ in the snapshot.
Meta note: Frankly I almost duplicated this other answer. The question there is about converting a directory into a subvolume, something you may or may not want to do. Because of this one difference I didn't simply point you to the other answer; I decided to explain the procedure in context of your question. But the difference is mostly in the question. The only difference in the procedure is whether you eventually change few names or not. If you find my answer useful then consider upvoting the linked one.
Snapshots can only be taken for subvolumes. There is no direct way to convert a directory into a subvolume.
cp -ax --reflink=always src/. dest
This will create just a normal copy of your directory but instead of copying all the file data it will be shared (=reflinked) with the original directory. Basically this is the same as a snapshot and if you want to have the copy in a separate subvolume you can just create an empty subvolume and copy the directory into it.
Depending on your data this may be faster than @Kamils answer because deleting all other files may take while for a huge number of files.