From 0a319a2b1dd8154e26008db2076b1854e1b553f7 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Thu, 5 Nov 2026 22:44:07 +0100 Subject: [PATCH] recreate: show --stats output without --info ArchiveRecreater.save logged the statistics via the default logger at INFO level, so "borg recreate --stats" printed nothing unless --info or -v was also given. Log them to the borg.output.stats topic logger, which --stats enables, like create and import-tar do. Co-Authored-By: Claude Opus 5.5 --- src/borg/archive.py | 3 ++- .../testsuite/archiver/recreate_cmd_test.py | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/borg/archive.py b/src/borg/archive.py index 733b96122c..87619e9fd7 100644 --- a/src/borg/archive.py +++ b/src/borg/archive.py @@ -1,6 +1,7 @@ import base64 import errno import json +import logging import os import posixpath import stat @@ -3532,7 +3533,7 @@ def save(self, archive, target, comment=None, delete_original=True): if delete_original: archive.delete() if self.stats: - log_multi(str(target), str(target.stats)) + log_multi(str(target), str(target.stats), logger=logging.getLogger("borg.output.stats")) def matcher_add_tagged_dirs(self, archive): """Add excludes to the matcher created by exclude_cache and exclude_if_present.""" diff --git a/src/borg/testsuite/archiver/recreate_cmd_test.py b/src/borg/testsuite/archiver/recreate_cmd_test.py index a0a07fd58f..e3ff6d43c5 100644 --- a/src/borg/testsuite/archiver/recreate_cmd_test.py +++ b/src/borg/testsuite/archiver/recreate_cmd_test.py @@ -332,6 +332,23 @@ def test_recreate_list_output(archivers, request): assert "- input/file5" not in output +def test_recreate_stats(archivers, request): + archiver = request.getfixturevalue(archivers) + cmd(archiver, "repo-create", RK_ENCRYPTION) + create_regular_file(archiver.input_path, "file1", size=1024) + create_regular_file(archiver.input_path, "file2", size=1024) + cmd(archiver, "create", "test", "input") + # --stats must show the statistics without also giving --info. + output = cmd(archiver, "recreate", "-a", "test", "--stats", "-e", "input/file2") + cmd(archiver, "check") + assert "Archive name: test" in output + assert "Number of files: 1" in output + # Without --stats, no statistics are shown. + output = cmd(archiver, "recreate", "-a", "test", "-e", "input/file1") + cmd(archiver, "check") + assert "Number of files:" not in output + + def test_comment(archivers, request): archiver = request.getfixturevalue(archivers) create_regular_file(archiver.input_path, "file1", size=1024 * 80)