borgmatic prune unexpectedly selects all hostnames on default settings #753
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What I'm trying to do and why
I noticed a lot of my backups were pruned automatically recently, including from devices I haven't updated recently. The recent deprecation of
prefixin the configuration file indicates thatmatch_archivesandarchive_name_formatshould be used instead. The default example config states:Moreover, it also states:
However, in the implementation of
make_prune_flagsthe following happens:From debugging this with
pudb, at thatelsestatementconfig.get('archive_name_format')returns an empty string, which goes against my understanding of what the configuration file claims. This then leads themake_match_archives_flagmethod to do:before it tries to derive match_archives. As a result, all archives, regardless of their hostname, are considered for pruning.
This may also affect other callers of
make_match_archives_flags, as I don't see any other functions implement a default for 'archive_name_format', but I did not investigate in detail.Steps to reproduce
match_archivesandarchive_name_formatleft unspecified on the different hosts.borgmatic prune --listActual behavior
Expected behavior
Other notes / implementation ideas
A workaround is to specify
match_archivesto besh:{hostname}-*explicitly. Looking at the source code, it might also work ifarchive_name_formatis explicitly defined, but I did not try this.This does not happen in 1.7.7, but I think that's because
prefixhadn't been deprecated yet.The fix might be to make sure that if
archive_name_formatis empty, that a default is assigned.borgmatic version
1.8.2
borgmatic installation method
emerge borgmatic
Borg version
borg 1.2.6
Python version
Python 3.11.5
Database version (if applicable)
No response
Operating system and version
NAME=Gentoo ID=gentoo PRETTY_NAME="Gentoo Linux" ANSI_COLOR="1;32" HOME_URL="https://www.gentoo.org/" SUPPORT_URL="https://www.gentoo.org/support/" BUG_REPORT_URL="https://bugs.gentoo.org/" VERSION_ID="2.14"
And yes, apparently the grand purge of all of my older backups took place sometime around March of this year, I just didn't notice it until now (at least according to data from my off-site backup location). From my understanding of borg, those old prunes are gone now, right? I haven't suffered data loss so it's not a huge issue, but boy am I glad I caught this issue now and not after actually needing all of the archives intact.
I did a bit more testing, and I can confirm that setting
archive_name_formatexplicitly to what's supposed to be the default value also leads to correct behavior.Thanks for taking the time to file this! Right now the documented
archive_name_formatdefault is only used to name the archive during archive creation (borgmatic create), and the documentation / schema comments are misleading in suggesting that the default applies to other actions as well. I agree with you that it would make more sense to also apply the default forpruneand other actions, specifically when deriving the match archives flags.That's unfortunately correct!
This is implemented in main and will be part of the next release. Thanks again for highlighting the need.
You should be aware though of this ticket: #748. If implemented as currently described, it would probably break your use case because it would start treating
{hostname}in the archive name format as*for purposes of filtering archives. I'm open to ideas on that ticket for how to solve the ask without breaking your use case!This has been released as part of borgmatic 1.8.3!