borg icon indicating copy to clipboard operation
borg copied to clipboard

borg2: enhance compact stats

Open ThomasWaldmann opened this issue 1 year ago • 5 comments

When building a ChunkIndex it currently starts from refcount=0 and then sets refcount=MAX_VALUE if a chunk is used.

That's how most of borg2 works now: it doesn't do refcounting anymore, just a boolean "do we have chunk X".

For better deduplication stats in borg compact, we could deviate from that in just borg compact and do precise refcounting without any additional effort.

Before persisting the ChunkIndex, we then need to set refcounts to MAX_VALUE, similar as we clean up the size values.

To consider:

  • what do we win?
  • we have the total size also in the archive metadata and can sum up all of these.
  • do we want to add per-directory stats / analytics? maybe even 2-pass stuff?

ThomasWaldmann avatar Sep 23 '24 23:09 ThomasWaldmann

Comment about what's interesting for practical usage: https://github.com/borgbackup/borg/issues/122#issuecomment-125700186

ThomasWaldmann avatar Sep 24 '24 09:09 ThomasWaldmann

This would definitely be useful: https://github.com/borgbackup/borg/issues/122#issuecomment-125915021

Question: if compression and/or obfuscation is enabled, would the size stats be given for the native file, pre-compression etc?

awgcooper avatar Sep 26 '24 02:09 awgcooper

Something else, not sure if it relates specifically to this: let's say I have a specific file backed up. I know this because it appears in a list contents of the most recent archive. Let's say I wanted to eliminate this file from the whole repo, how would I do that. Would I simply delete the first instance of it being backup up and by doing so that would automatically eliminate all dedups? If so, how would I find it? Fusermout?

awgcooper avatar Sep 26 '24 02:09 awgcooper

@awgcooper No, it does not work like that.

But you can use borg recreate to rewrite all the archives that contain the unwanted file (or the directory). Just be very careful with that and first use --dry-run --list to see if it does what you want.

ThomasWaldmann avatar Sep 26 '24 18:09 ThomasWaldmann

About "what do we win?" (see top post):

I guess the only thing would be the "deduplication factor", computed as:

DF = total_deduplicated_size_uncompressed / total_undeduplicated_size_uncompressed

The first value is just the sum of all plaintext chunk sizes. The second value is the sum of the total archive sizes of all archives.

To do that in a memory efficient way together with the already present stats (which need the compressed chunk sizes), we need to store the plaintext size AND the compressed size into the in-memory ChunkIndex we build.

So, in the end, we could show deduplication and compression factors.

ThomasWaldmann avatar Oct 12 '24 18:10 ThomasWaldmann

The refcount field was removed from the ChunkIndexEntry namedtuple.

compact now just uses a single bit (F_USED) to "know" which objects are used and which are not.

ThomasWaldmann avatar Nov 16 '24 17:11 ThomasWaldmann