debug strings

This commit is contained in:
Inex Code 2023-08-23 15:50:30 +03:00
parent f2c972ed5f
commit 8e60d11d5b
3 changed files with 23 additions and 0 deletions

View file

@ -332,23 +332,32 @@ class ResticBackupper(AbstractBackupper):
if folders is None or folders == []: if folders is None or folders == []:
raise ValueError("cannot restore without knowing where to!") raise ValueError("cannot restore without knowing where to!")
print("getting temp dir")
with tempfile.TemporaryDirectory() as temp_dir: with tempfile.TemporaryDirectory() as temp_dir:
print(f"temp dir is {temp_dir}")
if verify: if verify:
print("attempting verified restore")
self._raw_verified_restore(snapshot_id, target=temp_dir) self._raw_verified_restore(snapshot_id, target=temp_dir)
snapshot_root = temp_dir snapshot_root = temp_dir
for folder in folders: for folder in folders:
print(f"restoring {folder}")
src = join(snapshot_root, folder.strip("/")) src = join(snapshot_root, folder.strip("/"))
if not exists(src): if not exists(src):
raise ValueError( raise ValueError(
f"No such path: {src}. We tried to find {folder}" f"No such path: {src}. We tried to find {folder}"
) )
dst = folder dst = folder
print(f"syncing {src} to {dst}")
sync(src, dst) sync(src, dst)
else: # attempting inplace restore else: # attempting inplace restore
print("attempting inplace restore")
for folder in folders: for folder in folders:
print(f"restoring {folder}")
rmtree(folder) rmtree(folder)
print(f"removed {folder}")
mkdir(folder) mkdir(folder)
print(f"created {folder}")
self._raw_verified_restore(snapshot_id, target="/") self._raw_verified_restore(snapshot_id, target="/")
return return
@ -358,6 +367,7 @@ class ResticBackupper(AbstractBackupper):
"restore", snapshot_id, "--target", target, "--verify" "restore", snapshot_id, "--target", target, "--verify"
) )
print(f"starting restore with {restore_command}")
with subprocess.Popen( with subprocess.Popen(
restore_command, restore_command,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
@ -368,6 +378,7 @@ class ResticBackupper(AbstractBackupper):
# for some reason restore does not support # for some reason restore does not support
# nice reporting of progress via json # nice reporting of progress via json
output = handle.communicate()[0].decode("utf-8") output = handle.communicate()[0].decode("utf-8")
print(f"restore output: {output}")
if "restoring" not in output: if "restoring" not in output:
raise ValueError("cannot restore a snapshot: " + output) raise ValueError("cannot restore a snapshot: " + output)

View file

@ -38,6 +38,7 @@ def restore_snapshot(
""" """
The worker task that starts the restore process. The worker task that starts the restore process.
""" """
print(f"Restoring snapshot {snapshot.id} with strategy {strategy.name}")
Backups.restore_snapshot(snapshot, strategy) Backups.restore_snapshot(snapshot, strategy)
return True return True

View file

@ -278,23 +278,34 @@ class StoppedService:
""" """
def __init__(self, service: Service): def __init__(self, service: Service):
print("Stopping service - init")
self.service = service self.service = service
self.original_status = service.get_status() self.original_status = service.get_status()
print(f"Stopping service - original status: {self.original_status}")
def __enter__(self) -> Service: def __enter__(self) -> Service:
print(f"Stopping service - enter")
self.original_status = self.service.get_status() self.original_status = self.service.get_status()
print(f"Stopping service - original status: {self.original_status}")
if self.original_status != ServiceStatus.INACTIVE: if self.original_status != ServiceStatus.INACTIVE:
print("Original status is not inactive, stopping service")
self.service.stop() self.service.stop()
print("Waiting for service to stop")
wait_until_true( wait_until_true(
lambda: self.service.get_status() == ServiceStatus.INACTIVE, lambda: self.service.get_status() == ServiceStatus.INACTIVE,
timeout_sec=DEFAULT_START_STOP_TIMEOUT, timeout_sec=DEFAULT_START_STOP_TIMEOUT,
) )
print("Service stopped")
return self.service return self.service
def __exit__(self, type, value, traceback): def __exit__(self, type, value, traceback):
print(f"Stopping service - exit")
if self.original_status in [ServiceStatus.ACTIVATING, ServiceStatus.ACTIVE]: if self.original_status in [ServiceStatus.ACTIVATING, ServiceStatus.ACTIVE]:
print("Original status is active, starting service")
self.service.start() self.service.start()
print("Waiting for service to start")
wait_until_true( wait_until_true(
lambda: self.service.get_status() == ServiceStatus.ACTIVE, lambda: self.service.get_status() == ServiceStatus.ACTIVE,
timeout_sec=DEFAULT_START_STOP_TIMEOUT, timeout_sec=DEFAULT_START_STOP_TIMEOUT,
) )
print("Service started")