CLI: Allow snapshot argument for --stats command

This commit is contained in:
deajan 2024-05-21 23:49:43 +02:00
parent a4259caf86
commit 7734f6f9ff
3 changed files with 12 additions and 5 deletions

View file

@ -162,7 +162,11 @@ This is free software, and you are welcome to redistribute it under certain cond
help="Dump a specific file to stdout",
)
parser.add_argument(
"--stats", action="store_true", help="Get repository statistics"
"--stats",
type=str,
default=None,
required=False,
help="Get repository statistics. If snapshot id is given, only snapshots statistics will be shown."
)
parser.add_argument(
"--raw",
@ -471,6 +475,7 @@ This is free software, and you are welcome to redistribute it under certain cond
cli_args["op_args"] = {"path": args.dump}
elif args.stats or args.group_operation == "stats":
cli_args["operation"] = "stats"
cli_args["op_args"] = {"subject": args.stats}
elif args.raw or args.group_operation == "raw":
cli_args["operation"] = "raw"
cli_args["op_args"] = {"command": args.raw}

View file

@ -477,7 +477,7 @@ class NPBackupRunner:
and not current_permissions in required_permissions[operation]
):
self.write_logs(
f"Required permissions for operation '{operation}' must be in {required_permissions[operation]}, current permission is [{current_permissions}]",
f"Required permissions for operation '{operation}' must be one of {', '.join(required_permissions[operation])}, current permission is '{current_permissions}'",
level="critical",
)
raise PermissionError
@ -1362,11 +1362,11 @@ class NPBackupRunner:
@has_permission
@is_ready
@apply_config_to_restic_runner
def stats(self) -> bool:
def stats(self, subject: str = None) -> bool:
self.write_logs(
f"Getting stats of repo {self.repo_config.g('name')}", level="info"
)
result = self.restic_runner.stats()
result = self.restic_runner.stats(subject)
return result
@threaded

View file

@ -1055,7 +1055,7 @@ class ResticRunner:
return self.convert_to_json_output(result, output, msg=msg, **kwargs)
@check_if_init
def stats(self) -> Union[bool, str, dict]:
def stats(self, subject: str = None) -> Union[bool, str, dict]:
"""
Gives various repository statistics
"""
@ -1063,6 +1063,8 @@ class ResticRunner:
kwargs.pop("self")
cmd = f"stats"
if subject:
cmd += f" {subject}"
result, output = self.executor(cmd)
if result:
msg = f"Repo statistics command success"