Open dkacar-oradian opened 5 years ago
"Not reflinked" isn't that simple -- a file reflinked within the same subvolume (eg. cp
does that by default nowadays) should be included. Then, compsize cares about extents not files, and a file may have reflinked extents even within itself.
Thus, I wonder if an argument like -s $DIR
that does set subtraction of extents would fit your use cases. That is: to get all extents that are included in the primary directory but not in the subtracted one.
Well, I currently have a really simple use case. All of my subvolumes are Postgres data directories. The one called mirror
is a Postgres slave which is in constant replication from the master. From time to time I create a snapshot (in the snapshot
directory) from the mirror
subvolume and start master Postgres database on the snapshot
subvolume (on another port). So I don't have reflinks from cp
. Data in the mirror
subvolume is originally filled by rsync
from the backup server and I don't know if rsync
does something with reflinks.
The more complex case would be creating snapshot2
subvolume from snapshot1
(which has been created from mirror
). If compsize -s snapshot1 snapshot2
would show me only extents for which snapshot2
is an exclusive owner that would be great.
@dkacar-oradian I did something along these lines using btrfs-python: https://github.com/daviessm/btrfs-snapshots-diff/blob/master/btrfs-subvol-size.py
If you cut out most of the printing lines the end result should be the answer to the question "how much space would I gain if I deleted these files in this subvolume?" - where "these files" could the the entire subvolume.
PS it's a bit slow for large subvolumes.
Would it be possible to add a bit of code to show exclusive usage for subvolume? The only way to do that that I've found on the Internet seems to be to enable quota and then use
btrfs qgroup show
. However, when I enable quota btrfs becomes unusable for a long time (at least 15 minutes) after snapshot creation, so I can't afford to do that.Right now I have something like this:
snapshots/bckash_6432
was created as a snapshot ofmirrors/prod-db-c01_5432
. Then a lot of files in the snapshot were deleted and a few were changed. So I'd like to know how much its exclusive usage is. If I callbtrfs-compsize
on both directories I get this:I don't see if it's possible to calculate the exclusive usage for
snapshots/bckash_6432
from these numbers. So would it be possible to add a command line flag which would calculate usage only for files which are not reflinked? Then I could callbtrfs-compsize
without that flag on themirror
subvolume and after that call it with the flag on thesnapshot
subvolume. Any other method would be fine as well, this just looks as the simplest. But I don't quite understand how the code works, so I could be wrong.