Skip to content

Commit

Permalink
backup feature: implemented --dump option (dumps backup extract to di…
Browse files Browse the repository at this point in the history
…rectory)
  • Loading branch information
lirazsiri committed Aug 27, 2013
1 parent 09e5e8c commit d16406f
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 4 deletions.
12 changes: 12 additions & 0 deletions backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# published by the Free Software Foundation; either version 3 of
# the License, or (at your option) any later version.
#

import os
from os.path import exists, join

Expand All @@ -23,6 +24,8 @@
import duplicity
import mysql

import executil

from utils import AttrDict

class ProfilePaths(Paths):
Expand Down Expand Up @@ -246,6 +249,15 @@ def run(self, debug=False):

backup_command.run(passphrase, self.credentials, debug=debug)

def dump(self, path):

def r(p):
return join(path, p.lstrip('/'))

shutil.copytree(self.extras_paths.path, r(self.extras_paths.path))
executil.getoutput("tar --create --files-from=%s | tar --extract --directory %s" %
(self.extras_paths.fsdelta_olist, executil.mkarg(path)))

def cleanup(self):
_rmdir(self.extras_paths.path)

34 changes: 30 additions & 4 deletions cmd_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
Default overrides read from $CONF_OVERRIDES
Options:
--dump=path/to/extract/ Dump a raw backup extract to path
Tip: tklbam-restore path/to/raw/extract/
--resume Resume aborted backup session
--disable-resume Disable implicit --resume when rerunning an aborted backup
Expand Down Expand Up @@ -72,6 +75,7 @@
"""

import os
from os.path import *

import sys
Expand Down Expand Up @@ -134,6 +138,7 @@ def main():
try:
opts, args = getopt.gnu_getopt(sys.argv[1:], 'qsh',
['help',
'dump=',
'skip-files', 'skip-database', 'skip-packages',
'debug',
'resume', 'disable-resume',
Expand All @@ -144,6 +149,8 @@ def main():
except getopt.GetoptError, e:
usage(e)

opt_dump_path = None

opt_debug = False
opt_resume = None
opt_disable_resume = False
Expand All @@ -153,10 +160,25 @@ def main():
conf.secretfile = registry.path.secret

for opt, val in opts:
if opt in ('-s', '--simulate'):
if opt == '--dump':
opt_dump_path = val

if exists(opt_dump_path):
if not isdir(opt_dump_path):
fatal("--dump=%s is not a directory" % opt_dump_path)

if os.listdir(opt_dump_path) != []:
fatal("--dump=%s is not an empty directory" % opt_dump_path)

else:
os.mkdir(opt_dump_path)

conf.verbose = False

elif opt in ('-s', '--simulate'):
conf.simulate = True

if opt == '--resume':
elif opt == '--resume':
opt_resume = True

elif opt == '--disable-resume':
Expand Down Expand Up @@ -316,11 +338,15 @@ def main():

hooks.backup.inspect(b.extras_paths.path)

if opt_debug:
if opt_debug or opt_dump_path:
trap.close()
trap = None

b.run(opt_debug)
if opt_dump_path:
b.dump(opt_dump_path)
else:
b.run(opt_debug)

hooks.backup.post()
except:
if not conf.checkpoint_restore:
Expand Down
4 changes: 4 additions & 0 deletions docs/tklbam-backup.html
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,10 @@ <h1>OPTIONS</h1>
<col class="description" />
<tbody valign="top">
<tr><td class="option-group">
<kbd><span class="option">--dump=<var>DIR</var></span></kbd></td>
<td>Dump a raw backup extract to path.
Tip: tklbam-restore path/to/raw/extract/</td></tr>
<tr><td class="option-group">
<kbd><span class="option">--resume</span></kbd></td>
<td>Resume aborted backup session</td></tr>
<tr><td class="option-group" colspan="2">
Expand Down
5 changes: 5 additions & 0 deletions docs/tklbam-backup.man
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ mysql:drupal6
.SH OPTIONS
.INDENT 0.0
.TP
.BI \-\-dump\fB= DIR
.
Dump a raw backup extract to path.
Tip: tklbam\-restore path/to/raw/extract/
.TP
.B \-\-resume
.
Resume aborted backup session
Expand Down
3 changes: 3 additions & 0 deletions docs/tklbam-backup.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ Examples::
OPTIONS
=======

--dump=DIR Dump a raw backup extract to path.
Tip: tklbam-restore path/to/raw/extract/

--resume Resume aborted backup session

--disable-resume Disable implicit --resume when rerunning an aborted backup
Expand Down

0 comments on commit d16406f

Please sign in to comment.