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 ----------