diff --git a/.gitignore b/.gitignore index 1870d6f..f4f5714 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,6 @@ build datadb.egg-info dist test.ini +datadb.key +*__pycache__* + diff --git a/README.md b/README.md index 5aa804c..1b3b97c 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,13 @@ Restore operations have a degree of sanity checking. Upon a successful restore, Command line usage is agnostic to the underlying transport protocol used. +### Testing + +The following environment variables can be used to ease testing: + +* DATADB_CONF=./example.ini +* DATADB_KEYPATH=./datadb.key + ## TODO * Fix hard coded stuff mentioned above diff --git a/datadb/__init__.py b/datadb/__init__.py index 3b93d0b..27fdca4 100755 --- a/datadb/__init__.py +++ b/datadb/__init__.py @@ -1 +1 @@ -__version__ = "0.0.2" +__version__ = "0.0.3" diff --git a/datadb/datadb.py b/datadb/datadb.py index e79662e..7d2ffef 100755 --- a/datadb/datadb.py +++ b/datadb/datadb.py @@ -9,7 +9,7 @@ from enum import Enum import subprocess from requests import get,put,head -SSH_KEY_PATH = '/root/.ssh/datadb.key' +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)] DATADB_HTTP_API = 'http://datadb.services.davepedu.com:4875/cgi-bin/' @@ -93,6 +93,12 @@ def backup(profile, conf, force=False): if dest.scheme == 'rsync': args = RSYNC_DEFAULT_ARGS[:] + # Excluded paths + for exclude_path in conf["exclude"].split(","): + if not exclude_path == "": + args.append("--exclude") + args.append(exclude_path) + # Add local dir args.append(normpath(conf["dir"])+'/') @@ -114,7 +120,15 @@ def backup(profile, conf, force=False): # CD to local source dir # create tarball # http PUT file to backup server - args_tar = ['tar', '--exclude=.datadb.lock', '-zcv', './'] + args_tar = ['tar', '--exclude=.datadb.lock'] + + # Excluded paths + for exclude_path in conf["exclude"].split(","): + if not exclude_path == "": + args_tar.append("--exclude") + 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"])] print("Tar backup call: {} | {}".format(' '.join(args_tar), ' '.join(args_curl))) @@ -164,6 +178,7 @@ def main(): restore_postexec= export_preexec= export_postexec= + exclude= ---------------------------- Each [section] defines one backup task. @@ -193,6 +208,8 @@ 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. + """ conf_path = environ["DATADB_CONF"] if "DATADB_CONF" in environ else "/etc/datadb.ini" diff --git a/example.ini b/example.ini new file mode 100644 index 0000000..a484d9f --- /dev/null +++ b/example.ini @@ -0,0 +1,21 @@ +[testing_rsync] +uri=rsync://datadb.services.davepedu.com/testing_rsync +dir=/Users/dave/Downloads/rtest/src +keep=1 +auth= +restore_preexec= +restore_postexec= +export_preexec= +export_postexec= +exclude=c,d + +[testing_archive] +uri=archive://datadb.services.davepedu.com/testing_archive +dir=/Users/dave/Downloads/rtest/src +keep=1 +auth= +restore_preexec= +restore_postexec= +export_preexec= +export_postexec= +exclude=c,d