From 7d6cde8053345ff13e6ed2c66a0fcdd2b8616ea2 Mon Sep 17 00:00:00 2001 From: Markus Zolliker Date: Tue, 20 Oct 2026 16:13:56 +0200 Subject: [PATCH] wait for name resolution is up before doing restore --- repo_sync.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/repo_sync.py b/repo_sync.py index 1288761..96df829 100644 --- a/repo_sync.py +++ b/repo_sync.py @@ -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 ----------