From 3fb5d3f227c0eede17181fad6bdb3418a1e97de5 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Thu, 10 Oct 2024 00:33:15 +0200 Subject: [PATCH] recreate: do not recreate protected archives --- src/borg/archiver/recreate_cmd.py | 5 +++-- src/borg/testsuite/archiver/recreate_cmd_test.py | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/borg/archiver/recreate_cmd.py b/src/borg/archiver/recreate_cmd.py index 80ef33bff..26efe46fc 100644 --- a/src/borg/archiver/recreate_cmd.py +++ b/src/borg/archiver/recreate_cmd.py @@ -37,8 +37,9 @@ class RecreateMixIn: dry_run=args.dry_run, timestamp=args.timestamp, ) - - for archive_info in manifest.archives.list_considering(args): + archive_infos = manifest.archives.list_considering(args) + archive_infos = [ai for ai in archive_infos if "@PROT" not in ai.tags] + for archive_info in archive_infos: if recreater.is_temporary_archive(archive_info.name): continue name, hex_id = archive_info.name, bin_to_hex(archive_info.id) diff --git a/src/borg/testsuite/archiver/recreate_cmd_test.py b/src/borg/testsuite/archiver/recreate_cmd_test.py index d55209df4..7c2dc879e 100644 --- a/src/borg/testsuite/archiver/recreate_cmd_test.py +++ b/src/borg/testsuite/archiver/recreate_cmd_test.py @@ -274,3 +274,18 @@ def test_comment(archivers, request): assert "Comment: modified comment" in cmd(archiver, "info", "-a", "test2") assert "Comment: " + os.linesep in cmd(archiver, "info", "-a", "test3") assert "Comment: preserved comment" in cmd(archiver, "info", "-a", "test4") + + +def test_recreate_ignore_protected(archivers, request): + archiver = request.getfixturevalue(archivers) + create_test_files(archiver.input_path) + create_regular_file(archiver.input_path, "file1", size=1024) + create_regular_file(archiver.input_path, "file2", size=1024) + cmd(archiver, "repo-create", RK_ENCRYPTION) + cmd(archiver, "create", "archive", "input") + cmd(archiver, "tag", "--add=@PROT", "archive") + cmd(archiver, "recreate", "archive", "-e", "input") # this would normally remove all from archive + listing = cmd(archiver, "list", "archive", "--short") + # archive was protected, so recreate ignored it: + assert "file1" in listing + assert "file2" in listing