From 1b680531eed1dafa12220aaf2aec56e10c053361 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Thu, 26 Sep 2024 09:10:52 +0200 Subject: [PATCH 1/2] repo-list --short: only print archive IDs Needed to change this because listing just the archive names is pretty useless if names are not unique. The short list is likely mostly used by scripts to iterate over all archives, so outputting IDs is better. --- src/borg/archiver/repo_list_cmd.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/borg/archiver/repo_list_cmd.py b/src/borg/archiver/repo_list_cmd.py index 29682d30d9..5ac29be03d 100644 --- a/src/borg/archiver/repo_list_cmd.py +++ b/src/borg/archiver/repo_list_cmd.py @@ -20,7 +20,7 @@ def do_repo_list(self, args, repository, manifest): if args.format is not None: format = args.format elif args.short: - format = "{archive}{NL}" + format = "{id}{NL}" else: format = os.environ.get("BORG_RLIST_FORMAT", "{archive:<36} {time} [{id}]{NL}") formatter = ArchiveFormatter(format, repository, manifest, manifest.key, iec=args.iec) @@ -93,7 +93,7 @@ def build_parser_repo_list(self, subparsers, common_parser, mid_common_parser): ) subparser.set_defaults(func=self.do_repo_list) subparser.add_argument( - "--short", dest="short", action="store_true", help="only print the archive names, nothing else" + "--short", dest="short", action="store_true", help="only print the archive IDs, nothing else" ) subparser.add_argument( "--format", From 9b3a0023c3925d3690310183b8fa60a6676e2773 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Thu, 26 Sep 2024 09:27:43 +0200 Subject: [PATCH 2/2] repo-list: add hostname/username/comment to default format, reorder, adjust borg 1.x encouraged users to put everything into the archive name: - name of the dataset - timestamp (usually used to make the archive name unique) - maybe also hostname (when backing up to same repo from multiple hosts) - maybe also username (when backing up to same repo from multiple users) borg2 now discourages users from putting the timestamp into the name, because we rather want same name within a series of archives - thus, the field width for the name can be narrower. the ID of the archive is now the only unique identifier, thus it is moved to the leftmost place. 256bits (64 hex digits) was a bit much and as borg can also deal with abbreviated IDs, we only show 32bits (8 hex digits) by default. the ID is followed by the timestamp (also quite "interesting", because it usually differs for different archives). then following are: archive name, user name, host name - these might be always the same if there is only one series of archives in a repo. use 2 blanks separating the fields for better readability. --- docs/usage/repo-list.rst | 10 ++++++---- src/borg/archiver/repo_list_cmd.py | 4 +++- src/borg/testsuite/archiver/create_cmd.py | 4 ++-- src/borg/testsuite/archiver/repo_list_cmd.py | 17 +++++++++++------ src/borg/testsuite/archiver/transfer_cmd.py | 5 ++++- 5 files changed, 26 insertions(+), 14 deletions(-) diff --git a/docs/usage/repo-list.rst b/docs/usage/repo-list.rst index 00f9259087..e9fe6d65a4 100644 --- a/docs/usage/repo-list.rst +++ b/docs/usage/repo-list.rst @@ -5,9 +5,11 @@ Examples :: $ borg repo-list - Monday Mon, 2016-02-15 19:15:11 - repo Mon, 2016-02-15 19:26:54 - root-2016-02-15 Mon, 2016-02-15 19:36:29 - newname Mon, 2016-02-15 19:50:19 + 151b1a57 Mon, 2024-09-23 22:57:11 +0200 docs tw MacBook-Pro this is a comment + 3387a079 Thu, 2024-09-26 09:07:07 +0200 scripts tw MacBook-Pro + ca774425 Thu, 2024-09-26 10:05:23 +0200 scripts tw MacBook-Pro + ba56c4a5 Thu, 2024-09-26 10:12:45 +0200 src tw MacBook-Pro + 7567b79a Thu, 2024-09-26 10:15:07 +0200 scripts tw MacBook-Pro + 21ab3600 Thu, 2024-09-26 10:15:17 +0200 docs tw MacBook-Pro ... diff --git a/src/borg/archiver/repo_list_cmd.py b/src/borg/archiver/repo_list_cmd.py index 5ac29be03d..6214c2ae06 100644 --- a/src/borg/archiver/repo_list_cmd.py +++ b/src/borg/archiver/repo_list_cmd.py @@ -22,7 +22,9 @@ def do_repo_list(self, args, repository, manifest): elif args.short: format = "{id}{NL}" else: - format = os.environ.get("BORG_RLIST_FORMAT", "{archive:<36} {time} [{id}]{NL}") + format = os.environ.get( + "BORG_RLIST_FORMAT", "{id:.8} {time} {archive:<15} {username:<10} {hostname:<10} {comment:.40}{NL}" + ) formatter = ArchiveFormatter(format, repository, manifest, manifest.key, iec=args.iec) output_data = [] diff --git a/src/borg/testsuite/archiver/create_cmd.py b/src/borg/testsuite/archiver/create_cmd.py index d93a7652e2..08794a33e3 100644 --- a/src/borg/testsuite/archiver/create_cmd.py +++ b/src/borg/testsuite/archiver/create_cmd.py @@ -63,7 +63,7 @@ def test_basic_functionality(archivers, request): with changedir("output"): cmd(archiver, "extract", "test") - list_output = cmd(archiver, "repo-list", "--short") + list_output = cmd(archiver, "repo-list") assert "test" in list_output assert "test.2" in list_output @@ -532,7 +532,7 @@ def test_create_archivename_with_placeholder(archivers, request): name_given = "test-{now}" # placeholder in archive name gets replaced by borg name_expected = f"test-{ts}" # placeholder in f-string gets replaced by python cmd(archiver, "create", f"--timestamp={ts}", name_given, "input") - list_output = cmd(archiver, "repo-list", "--short") + list_output = cmd(archiver, "repo-list") assert name_expected in list_output diff --git a/src/borg/testsuite/archiver/repo_list_cmd.py b/src/borg/testsuite/archiver/repo_list_cmd.py index a8d87cb909..fc3b030678 100644 --- a/src/borg/testsuite/archiver/repo_list_cmd.py +++ b/src/borg/testsuite/archiver/repo_list_cmd.py @@ -25,13 +25,18 @@ def test_archives_format(archivers, request): cmd(archiver, "create", "--comment", "comment 1", "test-1", src_dir) cmd(archiver, "create", "--comment", "comment 2", "test-2", src_dir) output_1 = cmd(archiver, "repo-list") - output_2 = cmd(archiver, "repo-list", "--format", "{archive:<36} {time} [{id}]{NL}") + output_2 = cmd( + archiver, + "repo-list", + "--format", + "{id:.8} {time} {archive:<15} {username:<10} {hostname:<10} {comment:.40}{NL}", + ) assert output_1 == output_2 - output_1 = cmd(archiver, "repo-list", "--short") - assert output_1 == "test-1" + os.linesep + "test-2" + os.linesep - output_3 = cmd(archiver, "repo-list", "--format", "{name} {comment}{NL}") - assert "test-1 comment 1" + os.linesep in output_3 - assert "test-2 comment 2" + os.linesep in output_3 + output = cmd(archiver, "repo-list", "--short") + assert len(output) == 2 * 64 + 2 * len(os.linesep) + output = cmd(archiver, "repo-list", "--format", "{name} {comment}{NL}") + assert "test-1 comment 1" + os.linesep in output + assert "test-2 comment 2" + os.linesep in output def test_size_nfiles(archivers, request): diff --git a/src/borg/testsuite/archiver/transfer_cmd.py b/src/borg/testsuite/archiver/transfer_cmd.py index d178988ffe..84b9127e15 100644 --- a/src/borg/testsuite/archiver/transfer_cmd.py +++ b/src/borg/testsuite/archiver/transfer_cmd.py @@ -18,7 +18,7 @@ def test_transfer(archivers, request): original_location, input_path = archiver.repository_location, archiver.input_path def check_repo(): - listing = cmd(archiver, "repo-list", "--short") + listing = cmd(archiver, "repo-list") assert "arch1" in listing assert "arch2" in listing listing = cmd(archiver, "list", "--short", "arch1") @@ -93,6 +93,9 @@ def convert_tz(local_naive, tzoffset, tzinfo): for got_archive, expected_archive in zip(got["archives"], expected["archives"]): del got_archive["id"] + del got_archive["username"] # we didn't have this in the 1.x default format + del got_archive["hostname"] # we didn't have this in the 1.x default format + del got_archive["comment"] # we didn't have this in the 1.x default format del expected_archive["id"] del expected_archive["barchive"] # timestamps: