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

View file

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