Browse Source

Added date-matching support for list_considering (#7306)

added date-matching support for list_considering, fixes #7296

Co-authored-by: Michael Deyaso <mdeyaso@fusioniq.io>
Michael Deyaso 2 years ago
parent
commit
8af9eb47c2
2 changed files with 32 additions and 2 deletions
  1. 6 2
      src/borg/manifest.py
  2. 26 0
      src/borg/testsuite/archiver/rlist_cmd.py

+ 6 - 2
src/borg/manifest.py

@@ -164,8 +164,12 @@ class Archives(abc.MutableMapping):
             sort_by=args.sort_by.split(","),
             consider_checkpoints=consider_checkpoints,
             match=args.match_archives,
-            first=args.first,
-            last=args.last,
+            first=getattr(args, "first", None),
+            last=getattr(args, "last", None),
+            older=getattr(args, "older", None),
+            newer=getattr(args, "newer", None),
+            oldest=getattr(args, "oldest", None),
+            newest=getattr(args, "newest", None),
         )
 
     def set_raw_dict(self, d):

+ 26 - 0
src/borg/testsuite/archiver/rlist_cmd.py

@@ -40,6 +40,32 @@ class ArchiverTestCase(ArchiverTestCaseBase):
         self.assert_in("test-1 comment 1" + os.linesep, output_3)
         self.assert_in("test-2 comment 2" + os.linesep, output_3)
 
+    def test_date_matching(self):
+        self.cmd(f"--repo={self.repository_location}", "rcreate", RK_ENCRYPTION)
+        earliest_ts = "2022-11-20T23:59:59"
+        ts_in_between = "2022-12-18T23:59:59"
+        self.create_src_archive("archive1", ts=earliest_ts)
+        self.create_src_archive("archive2", ts=ts_in_between)
+        self.create_src_archive("archive3")
+        output = self.cmd(f"--repo={self.repository_location}", "rlist", "-v", "--oldest=23e", exit_code=2)
+        output = self.cmd(f"--repo={self.repository_location}", "rlist", "-v", "--oldest=1m", exit_code=0)
+        self.assert_in("archive1", output)
+        self.assert_in("archive2", output)
+        self.assert_not_in("archive3", output)
+
+        output = self.cmd(f"--repo={self.repository_location}", "rlist", "-v", "--newest=1m", exit_code=0)
+        self.assert_in("archive3", output)
+        self.assert_not_in("archive2", output)
+        self.assert_not_in("archive1", output)
+        output = self.cmd(f"--repo={self.repository_location}", "rlist", "-v", "--newer=1d", exit_code=0)
+        self.assert_in("archive3", output)
+        self.assert_not_in("archive1", output)
+        self.assert_not_in("archive2", output)
+        output = self.cmd(f"--repo={self.repository_location}", "rlist", "-v", "--older=1d", exit_code=0)
+        self.assert_in("archive1", output)
+        self.assert_in("archive2", output)
+        self.assert_not_in("archive3", output)
+
     def test_rlist_consider_checkpoints(self):
         self.cmd(f"--repo={self.repository_location}", "rcreate", RK_ENCRYPTION)
         self.cmd(f"--repo={self.repository_location}", "create", "test1", src_dir)