Skip to content

Commit

Permalink
repo-list: add hostname/username/comment to default format, reorder, …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
ThomasWaldmann committed Sep 26, 2024
1 parent 1b68053 commit a06c7dd
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 14 deletions.
10 changes: 6 additions & 4 deletions docs/usage/repo-list.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
...

4 changes: 3 additions & 1 deletion src/borg/archiver/repo_list_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
4 changes: 2 additions & 2 deletions src/borg/testsuite/archiver/create_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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


Expand Down
14 changes: 8 additions & 6 deletions src/borg/testsuite/archiver/repo_list_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ 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}{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):
Expand Down
5 changes: 4 additions & 1 deletion src/borg/testsuite/archiver/transfer_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit a06c7dd

Please sign in to comment.