Browse Source

Add exclude flag

master
Dave Pedu 4 years ago
parent
commit
2b8221c8f5
5 changed files with 51 additions and 3 deletions
  1. +3
    -0
      .gitignore
  2. +7
    -0
      README.md
  3. +1
    -1
      datadb/__init__.py
  4. +19
    -2
      datadb/datadb.py
  5. +21
    -0
      example.ini

+ 3
- 0
.gitignore View File

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


+ 7
- 0
README.md 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.

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


+ 1
- 1
datadb/__init__.py View File

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

+ 19
- 2
datadb/datadb.py View File

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


+ 21
- 0
example.ini 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

Loading…
Cancel
Save