This commit is contained in:
dave 2017-04-22 00:06:12 -07:00
parent 0596899040
commit 49ff19b088
2 changed files with 128 additions and 120 deletions

View File

@ -8,12 +8,14 @@ from os import chmod, chown, stat, environ
from enum import Enum
import subprocess
from requests import get, put, head
import json
SSH_KEY_PATH = environ["DATADB_KEYPATH"] if "DATADB_KEYPATH" in environ else '/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)]
DATADB_HTTP_API = 'http://datadb.services.davepedu.com:4875/cgi-bin/'
class SyncStatus(Enum):
"Data is on local disk"
DATA_AVAILABLE = 1
@ -125,7 +127,8 @@ def backup(profile, conf, force=False):
# confirm completion if backup wasnt already in place
if not conf["inplace"]:
put(DATADB_HTTP_API+'new_backup', params={'proto':'rsync', 'name':profile, 'token': token, 'keep':conf["keep"]})
put(DATADB_HTTP_API + 'new_backup', params={'proto': 'rsync', 'name': profile, 'token': token,
'keep': conf["keep"]})
elif dest.scheme == 'archive':
# CD to local source dir
@ -141,7 +144,8 @@ def backup(profile, conf, force=False):
args_tar.append(exclude_path)
args_tar += ['-zcv', './']
args_curl = ['curl', '-v', '-XPUT', '--data-binary', '@-', '{}new_backup?proto=archive&name={}&keep={}'.format(DATADB_HTTP_API, profile, conf["keep"])]
args_curl = ['curl', '-v', '-XPUT', '--data-binary', '@-', '{}new_backup?proto=archive&name={}&keep={}'.
format(DATADB_HTTP_API, profile, conf["keep"])]
print("Tar backup call: {} | {}".format(' '.join(args_tar), ' '.join(args_curl)))
@ -204,7 +208,8 @@ def main():
Valid protocols:
rsync - rsync executed over SSH. The local dir will be synced with the remote backup dir using rsync.
archive - tar archives transported over HTTP. The local dir will be tarred and PUT to the backup server's remote dir via http.
archive - tar archives transported over HTTP. The local dir will be tarred and PUT to the backup server's
remote dir via http.
*dir*: Local dir for this backup
@ -220,9 +225,11 @@ def main():
*export_postexec*: Shell command to exec after pushing data
*exclude*: if the underlying transport method supports excluding paths, a comma separated list of paths to exclude. Applies to backup operations only.
*exclude*: if the underlying transport method supports excluding paths, a comma separated list of paths to exclude.
Applies to backup operations only.
*inplace*: rsync only. if enabled, the server will keep only a single copy that you will rsync over. intended for single copies of LARGE datasets. overrides "keep".
*inplace*: rsync only. if enabled, the server will keep only a single copy that you will rsync over. intended for
single copies of LARGE datasets. overrides "keep".
"""
@ -252,10 +259,12 @@ def main():
parser = argparse.ArgumentParser(description="Backupdb Agent depends on config: /etc/datadb.ini")
parser.add_argument('-f', '--force', default=False, action='store_true', help='force restore operation if destination data already exists')
parser.add_argument('-f', '--force', default=False, action='store_true',
help='force restore operation if destination data already exists')
parser.add_argument('-n', '--no-exec', default=False, action='store_true', help='don\'t run pre/post-exec commands')
parser.add_argument('-b', '--no-pre-exec', default=False, action='store_true', help='don\'t run pre-exec commands')
parser.add_argument('-m', '--no-post-exec', default=False, action='store_true', help='don\'t run post-exec commands')
parser.add_argument('-m', '--no-post-exec', default=False, action='store_true',
help='don\'t run post-exec commands')
parser.add_argument('profile', type=str, choices=config.keys(), help='Profile to restore')
@ -268,11 +277,11 @@ def main():
subparser_modes = parser.add_subparsers(dest='mode', help='modes (only "rsync")')
subparser_backup = subparser_modes.add_parser('backup', help='backup to datastore')
subparser_backup = subparser_modes.add_parser('backup', help='backup to datastore') # NOQA
subparser_restore = subparser_modes.add_parser('restore', help='restore from datastore')
subparser_restore = subparser_modes.add_parser('restore', help='restore from datastore') # NOQA
subparser_status = subparser_modes.add_parser('status', help='get info for profile')
subparser_status = subparser_modes.add_parser('status', help='get info for profile') # NOQA
args = parser.parse_args()

View File

@ -10,5 +10,4 @@ setup(name='datadb',
author='dpedu',
author_email='dave@davepedu.com',
packages=['datadb'],
scripts=['bin/datadb']
)
scripts=['bin/datadb'])