Handle when backup doesn't exit during restore attempt

This commit is contained in:
dave 2015-12-29 22:38:04 -08:00
parent cd9c0f0044
commit d274d11d9d
1 changed files with 7 additions and 1 deletions

View File

@ -7,7 +7,7 @@ from os.path import normpath, join, exists
from os import chmod, chown, stat, environ from os import chmod, chown, stat, environ
from enum import Enum from enum import Enum
import subprocess import subprocess
from requests import get,put from requests import get,put,head
SSH_KEY_PATH = '/root/.ssh/datadb.key' 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)] 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"]) original_perms = stat(conf["dir"])
dest = urlparse(conf["uri"]) 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': if dest.scheme == 'rsync':
args = RSYNC_DEFAULT_ARGS[:] args = RSYNC_DEFAULT_ARGS[:]