fix: apply --force-keep to timestamp subdirectories instead of backup folders

- Change --force-keep semantics to skip the last N subdirectories inside each
  backup-docker-to-local folder
- Remove old behavior that skipped entire backup folders in --all mode
- Update CLI help text to reflect the new behavior
- Align unit and E2E tests with timestamp-based force-keep semantics

https://chatgpt.com/share/695d1ed9-44f0-800f-a236-e903c61036cb
This commit is contained in:
2026-01-06 15:40:16 +01:00
parent 20a850ee21
commit f402cea6f2
3 changed files with 53 additions and 30 deletions

View File

@@ -153,10 +153,10 @@ class CleanupBackupsUsingDirvalTests(unittest.TestCase):
self.assertFalse(self.timeoutC.exists())
self.assertTrue(self.goodX.exists())
self.assertFalse(self.badY.exists())
def test_all_mode_force_keep_skips_last_backup_folder(self):
# Given backup folders: ID1, ID2 (sorted)
# --force-keep 1 should skip ID2 completely.
def test_all_mode_force_keep_skips_last_timestamp_subdir_per_backup_folder(self):
# Subdirs are sorted by name.
# --force-keep 1 skips the last subdir inside each backup-docker-to-local folder.
rc, out, err, _ = self.run_main(
[
"--backups-root",
@@ -175,14 +175,14 @@ class CleanupBackupsUsingDirvalTests(unittest.TestCase):
)
self.assertEqual(rc, 0, msg=err or out)
# ID1 should be processed
self.assertTrue(self.goodA.exists())
self.assertFalse(self.badB.exists())
self.assertFalse(self.timeoutC.exists())
# ID1 sorted: badB, goodA, timeoutC -> timeoutC is skipped, others processed
self.assertTrue(self.goodA.exists(), "goodA should remain")
self.assertFalse(self.badB.exists(), "badB should be deleted")
self.assertTrue(self.timeoutC.exists(), "timeoutC should be skipped (kept)")
# ID2 should be untouched
self.assertTrue(self.goodX.exists())
self.assertTrue(self.badY.exists())
# ID2 sorted: badY, goodX -> goodX is skipped, badY processed
self.assertTrue(self.goodX.exists(), "goodX should be skipped (kept)")
self.assertFalse(self.badY.exists(), "badY should be processed and deleted")
def test_dirval_missing_errors(self):
rc, out, err, _ = self.run_main(