Add exclude flag

This commit is contained in:
Dave Pedu 2016-04-19 23:19:58 -07:00
parent 14467ab346
commit 2b8221c8f5
5 changed files with 51 additions and 3 deletions

3
.gitignore vendored
View File

@ -3,3 +3,6 @@ build
datadb.egg-info datadb.egg-info
dist dist
test.ini test.ini
datadb.key
*__pycache__*

View File

@ -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. 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 ## TODO
* Fix hard coded stuff mentioned above * Fix hard coded stuff mentioned above

View File

@ -1 +1 @@
__version__ = "0.0.2" __version__ = "0.0.3"

View File

@ -9,7 +9,7 @@ from enum import Enum
import subprocess import subprocess
from requests import get,put,head 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)] 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/' 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': if dest.scheme == 'rsync':
args = RSYNC_DEFAULT_ARGS[:] 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 # Add local dir
args.append(normpath(conf["dir"])+'/') args.append(normpath(conf["dir"])+'/')
@ -114,7 +120,15 @@ def backup(profile, conf, force=False):
# CD to local source dir # CD to local source dir
# create tarball # create tarball
# http PUT file to backup server # 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"])] 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))) print("Tar backup call: {} | {}".format(' '.join(args_tar), ' '.join(args_curl)))
@ -164,6 +178,7 @@ def main():
restore_postexec= restore_postexec=
export_preexec= export_preexec=
export_postexec= export_postexec=
exclude=
---------------------------- ----------------------------
Each [section] defines one backup task. Each [section] defines one backup task.
@ -193,6 +208,8 @@ def main():
*export_postexec*: Shell command to exec after pushing data *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" conf_path = environ["DATADB_CONF"] if "DATADB_CONF" in environ else "/etc/datadb.ini"

21
example.ini Normal file
View File

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