wait for name resolution is up before doing restore

This commit is contained in:
zolliker committed 2026-10-20 16:40:05 +02:00
1 parent 526b8983b9
commit 7d6cde8053
1 file changed
+16 -7
+16 -7
View File
@@ -40,10 +40,12 @@ def get_dirs():
def ssh(remote_cmd: str) -> subprocess.CompletedProcess:
log(f'> {remote_cmd}')
return subprocess.run(
SSH_OPTS.split() + [CENTRAL, remote_cmd],
capture_output=True, text=True,
)
try:
return subprocess.check_output(
SSH_OPTS.split() + [CENTRAL, remote_cmd], text=True)
except subprocess.CalledProcessError as e:
log(f'error: {e.output}')
return None
# ---------- rsync in both directions ----------
@@ -68,16 +70,23 @@ def restore() -> bool:
def cmd_restore():
for _ in range(60):
try:
socket.gethostbyname(CENTRAL.split('@')[-1])
break
except Exception as e:
log(repr(e))
time.sleep(1)
dorestore = f"{REMOTE_DIR}/do.restore"
if ssh(f"ls {dorestore}").returncode == 0:
if ssh(f"ls {dorestore}") is None:
log("no restore needed")
else:
if restore():
log("restore done")
ssh(f"rm {dorestore}")
return True
else:
log("restore failed")
else:
log("no restore needed")
# ---------- watcher ----------