diff --git a/src/borg/archive.py b/src/borg/archive.py index a2bc0fd502..b940c99740 100644 --- a/src/borg/archive.py +++ b/src/borg/archive.py @@ -2785,7 +2785,7 @@ def recreate(self, archive_id, target_name, delete_original, comment=None): target = self.create_target(archive, target_name) if self.exclude_if_present or self.exclude_caches: self.matcher_add_tagged_dirs(archive) - if self.matcher.empty() and not target.recreate_rechunkify and comment is None: + if self.matcher.empty() and not target.recreate_rechunkify and comment is None and self.timestamp is None: # nothing to do return False self.process_items(archive, target) diff --git a/src/borg/testsuite/archiver/recreate_cmd_test.py b/src/borg/testsuite/archiver/recreate_cmd_test.py index 25e0451187..608199650d 100644 --- a/src/borg/testsuite/archiver/recreate_cmd_test.py +++ b/src/borg/testsuite/archiver/recreate_cmd_test.py @@ -244,11 +244,13 @@ def test_recreate_keep_original_timestamp(archivers, request): info_orig = cmd(archiver, "info", "-a", "test0").splitlines() # this shall recreate the archive and keep the nominal timestamp time.sleep(1) - cmd(archiver, "recreate", "test0", "--comment", "test") + cmd(archiver, "recreate", "-a", "test0", "--comment", "test") info_recreated = cmd(archiver, "info", "-a", "test0").splitlines() nominal_orig = next(item for item in info_orig if item.startswith("Time (nominal):")) nominal_recreated = next(item for item in info_recreated if item.startswith("Time (nominal):")) assert nominal_orig == nominal_recreated + # the recreated archive must still contain the original items. + assert "input/file1" in cmd(archiver, "list", "test0", "--short") def test_recreate_with_given_timestamp(archivers, request): @@ -256,8 +258,10 @@ def test_recreate_with_given_timestamp(archivers, request): create_test_files(archiver.input_path) cmd(archiver, "repo-create", RK_ENCRYPTION) cmd(archiver, "create", "test0", "input") - # this shall recreate the archive with a different nominal timestamp - cmd(archiver, "recreate", "test0", "--timestamp", "1970-01-02T00:00:00", "--comment", "test") + # this shall recreate the archive with a different nominal timestamp. + # --timestamp is the only change requested, so this also checks that a timestamp + # change alone is enough to make recreate do the work instead of skipping the archive. + cmd(archiver, "recreate", "-a", "test0", "--timestamp", "1970-01-02T00:00:00") info = cmd(archiver, "info", "-a", "test0").splitlines() dtime = datetime(1970, 1, 2, 0, 0, 0).astimezone() # local time in local timezone s_time = dtime.strftime("%Y-%m-%d %H:%M:.. %z").replace("+", r"\+") @@ -267,6 +271,8 @@ def test_recreate_with_given_timestamp(archivers, request): s_time = dtime.strftime("%Y-%m-%d %H:..:.. %z").replace("+", r"\+") assert any([re.search(r"Time \(end\).+ %s" % s_time, item) for item in info]) assert any([re.search(r"Time \(start\).+ %s" % s_time, item) for item in info]) + # the recreated archive must still contain the original items. + assert "input/file1" in cmd(archiver, "list", "test0", "--short") def test_recreate_dry_run(archivers, request):