mirror of
https://github.com/netinvent/npbackup.git
synced 2025-11-09 13:44:51 +08:00
Avoid double logging with live output
This commit is contained in:
parent
1e81274773
commit
a5d2e79bc4
3 changed files with 21 additions and 4 deletions
|
|
@ -466,9 +466,9 @@ class NPBackupRunner:
|
|||
with pidfile.PIDFile(pid_file):
|
||||
# pylint: disable=E1102 (not-callable)
|
||||
result = fn(self, *args, **kwargs)
|
||||
except pidfile.AlreadyRunningError:
|
||||
except pidfile.AlreadyRunningError as exc:
|
||||
self.write_logs(
|
||||
f"There is already an {operation} operation running by NPBackup. Will not continue",
|
||||
f"There is already an {operation} operation running by NPBackup: {exc}. Will not continue",
|
||||
level="critical",
|
||||
)
|
||||
return False
|
||||
|
|
@ -827,8 +827,11 @@ class NPBackupRunner:
|
|||
)
|
||||
# Temporarily disable verbose and enable json result
|
||||
self.restic_runner.verbose = False
|
||||
# Temporarily disable CLI live output which we don't really need here
|
||||
self.restic_runner.live_output = False
|
||||
data = self.restic_runner.has_recent_snapshot(self.minimum_backup_age)
|
||||
self.restic_runner.verbose = self.verbose
|
||||
self.restic_runner.live_output = self.live_output
|
||||
if self.json_output:
|
||||
return data
|
||||
|
||||
|
|
|
|||
|
|
@ -543,9 +543,14 @@ class ResticRunner:
|
|||
We'll just check if snapshots can be read
|
||||
"""
|
||||
cmd = "snapshots"
|
||||
|
||||
# Disable live output for this check
|
||||
live_output = self.live_output
|
||||
self.live_output = False
|
||||
self._is_init, output = self.executor(
|
||||
cmd, timeout=FAST_COMMANDS_TIMEOUT, errors_allowed=True
|
||||
)
|
||||
self.live_output = live_output
|
||||
if not self._is_init:
|
||||
self.write_logs(output, level="error")
|
||||
return self._is_init
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ def serialize_datetime(obj):
|
|||
|
||||
def entrypoint(*args, **kwargs):
|
||||
json_output = kwargs.pop("json_output")
|
||||
|
||||
|
||||
npbackup_runner = NPBackupRunner()
|
||||
npbackup_runner.repo_config = kwargs.pop("repo_config")
|
||||
npbackup_runner.dry_run = kwargs.pop("dry_run")
|
||||
|
|
@ -46,7 +46,16 @@ def entrypoint(*args, **kwargs):
|
|||
)
|
||||
if not json_output:
|
||||
if not isinstance(result, bool):
|
||||
logger.info(f"{result}")
|
||||
|
||||
# We need to temprarily remove the stdout handler
|
||||
# Since we already get live output from the runner
|
||||
# But we still need to log the result to our logfile
|
||||
for handler in logger.handlers:
|
||||
if handler.stream == sys.stdout:
|
||||
logger.removeHandler(handler)
|
||||
break
|
||||
logger.info(f"\n{result}")
|
||||
logger.addHandler(handler)
|
||||
logger.info(f"Operation finished with {'success' if result else 'failure'}")
|
||||
else:
|
||||
print(json.dumps(result, default=serialize_datetime))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue