borgbackup / borg

Deduplicating archiver with compression and authenticated encryption.
https://www.borgbackup.org/
Other
11.2k stars 742 forks source link

Add `borg prune --keep-all` #6656

Open PhrozenByte opened 2 years ago

PhrozenByte commented 2 years ago

/kind enhancement

I have created a Borg repo that I use for manual backups only. Since I don't have a retention policy for this Borg repo either, I don't run borg prune at the moment. However, I just noticed that borg prune has another feature besides removing old archives according to a retention policy: removing old checkpoints.

Also, prune automatically removes checkpoint archives (incomplete archives left behind by interrupted backup runs) except if the checkpoint is the latest archive (and thus still needed). Checkpoint archives are not considered when comparing archive counts against the retention limits (--keep-X).

Since checkpoints aren't listed by borg list by default, quite a lot of checkpoints can accumulate before one notices it.

Right now I can't easily remove just old checkpoints from a Borg repo; passing no --keep-* option to borg prune yields the error:

At least one of the "keep-within", "keep-last", "keep-secondly", "keep-minutely", "keep-hourly", "keep-daily", "keep-weekly", "keep-monthly" or "keep-yearly" settings must be specified.

One can work around this error by using a very large number for --keep-last, e.g. --keep-last 1000000000. Another solution is to mimic borg prune's behaviour by using borg list --consider-checkpoints, a little sed magic and borg delete.

IMO this is a reasonable use case and Borg should support it without taking such workarounds.

Thus I'd like to suggest adding a --keep-all option to borg prune, specifically telling borg prune not to remove any actual archive, but just old checkpoints as explained before. Passing --keep-all with any other --keep-* option should probably thrown an error.

ThomasWaldmann commented 2 years ago

Considering that the default is to erase anything that is not explicitly kept, changing the behaviour for giving no --keep-* option does not sound like a good idea (because that would mean "erase all").

Yeah, we could add a --keep-all as an alias for --keep-latest <many_or_infinite>, but that's just cosmetics.

BTW, way more important is that you still use the right --prefix so prune stays inside the right backup set / sequence when determining the latest (checkpoint) archive of that set / sequence.

PhrozenByte commented 2 years ago

Considering that the default is to erase anything that is not explicitly kept, changing the behaviour for giving no --keep-* option does not sound like a good idea (because that would mean "erase all").

Just to clarify, I didn't mean to suggest that. My description might have given a false impression about that, sorry for the misunderstanding.

Yeah, we could add a --keep-all as an alias for --keep-latest <many_or_infinite>, but that's just cosmetics.

Indeed. I chose to use --keep-last 1000000000 in the meantime, adding --keep-all as an alias for --keep-last <infinite> would be great :+1:

BTW, way more important is that you still use the right --prefix so prune stays inside the right backup set / sequence when determining the latest (checkpoint) archive of that set / sequence.

Thanks for the heads up! Since I use a distinct Borg repo for my manual backups it doesn't really apply to my personal use case, but you're right, for Borg repos with multiple backup sets it definitely makes a huge difference.

#edit: It's --keep-last, not --keep-latest, my bad :see_no_evil: