From d274d11d9d5a30577f57c7613fb3012f0603d363 Mon Sep 17 00:00:00 2001 From: dave Date: Tue, 29 Dec 2015 22:38:04 -0800 Subject: [PATCH] Handle when backup doesn't exit during restore attempt --- datadb/datadb.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/datadb/datadb.py b/datadb/datadb.py index cb08e36..b4001b8 100755 --- a/datadb/datadb.py +++ b/datadb/datadb.py @@ -7,7 +7,7 @@ from os.path import normpath, join, exists from os import chmod, chown, stat, environ from enum import Enum import subprocess -from requests import get,put +from requests import get,put,head SSH_KEY_PATH = '/root/.ssh/datadb.key' RSYNC_DEFAULT_ARGS = ['rsync', '-avzr', '--exclude=.datadb.lock', '--whole-file', '--one-file-system', '--delete', '-e', 'ssh -i {} -p 4874 -o StrictHostKeyChecking=no'.format(SSH_KEY_PATH)] @@ -32,6 +32,12 @@ def restore(profile, conf, force=False): #remote_uri, local_dir, identity='/root original_perms = stat(conf["dir"]) dest = urlparse(conf["uri"]) + status_code = head(DATADB_HTTP_API+'get_backup', params={'proto':'rsync', 'name':profile}).status_code + if status_code: + print("Connected to datadb, but datasource '{}' doesn't exist. Exiting".format(profile)) + # TODO: special exit code >1 to indicate this? + return + if dest.scheme == 'rsync': args = RSYNC_DEFAULT_ARGS[:]