mirror of
https://github.com/netinvent/npbackup.git
synced 2025-11-11 14:42:37 +08:00
CLI: Allow snapshot argument for --stats command
This commit is contained in:
parent
a4259caf86
commit
7734f6f9ff
3 changed files with 12 additions and 5 deletions
|
|
@ -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",
|
help="Dump a specific file to stdout",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
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(
|
parser.add_argument(
|
||||||
"--raw",
|
"--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}
|
cli_args["op_args"] = {"path": args.dump}
|
||||||
elif args.stats or args.group_operation == "stats":
|
elif args.stats or args.group_operation == "stats":
|
||||||
cli_args["operation"] = "stats"
|
cli_args["operation"] = "stats"
|
||||||
|
cli_args["op_args"] = {"subject": args.stats}
|
||||||
elif args.raw or args.group_operation == "raw":
|
elif args.raw or args.group_operation == "raw":
|
||||||
cli_args["operation"] = "raw"
|
cli_args["operation"] = "raw"
|
||||||
cli_args["op_args"] = {"command": args.raw}
|
cli_args["op_args"] = {"command": args.raw}
|
||||||
|
|
|
||||||
|
|
@ -477,7 +477,7 @@ class NPBackupRunner:
|
||||||
and not current_permissions in required_permissions[operation]
|
and not current_permissions in required_permissions[operation]
|
||||||
):
|
):
|
||||||
self.write_logs(
|
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",
|
level="critical",
|
||||||
)
|
)
|
||||||
raise PermissionError
|
raise PermissionError
|
||||||
|
|
@ -1362,11 +1362,11 @@ class NPBackupRunner:
|
||||||
@has_permission
|
@has_permission
|
||||||
@is_ready
|
@is_ready
|
||||||
@apply_config_to_restic_runner
|
@apply_config_to_restic_runner
|
||||||
def stats(self) -> bool:
|
def stats(self, subject: str = None) -> bool:
|
||||||
self.write_logs(
|
self.write_logs(
|
||||||
f"Getting stats of repo {self.repo_config.g('name')}", level="info"
|
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
|
return result
|
||||||
|
|
||||||
@threaded
|
@threaded
|
||||||
|
|
|
||||||
|
|
@ -1055,7 +1055,7 @@ class ResticRunner:
|
||||||
return self.convert_to_json_output(result, output, msg=msg, **kwargs)
|
return self.convert_to_json_output(result, output, msg=msg, **kwargs)
|
||||||
|
|
||||||
@check_if_init
|
@check_if_init
|
||||||
def stats(self) -> Union[bool, str, dict]:
|
def stats(self, subject: str = None) -> Union[bool, str, dict]:
|
||||||
"""
|
"""
|
||||||
Gives various repository statistics
|
Gives various repository statistics
|
||||||
"""
|
"""
|
||||||
|
|
@ -1063,6 +1063,8 @@ class ResticRunner:
|
||||||
kwargs.pop("self")
|
kwargs.pop("self")
|
||||||
|
|
||||||
cmd = f"stats"
|
cmd = f"stats"
|
||||||
|
if subject:
|
||||||
|
cmd += f" {subject}"
|
||||||
result, output = self.executor(cmd)
|
result, output = self.executor(cmd)
|
||||||
if result:
|
if result:
|
||||||
msg = f"Repo statistics command success"
|
msg = f"Repo statistics command success"
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue