Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 82 lines (60 sloc) 2.371 kB
767facb @lirazsiri cleanup whitespace
lirazsiri authored
1 #
d740e7a @lirazsiri updated copyright year
lirazsiri authored
2 # Copyright (c) 2010-2012 Liraz Siri <liraz@turnkeylinux.org>
767facb @lirazsiri cleanup whitespace
lirazsiri authored
3 #
0c11ee9 @lirazsiri added copyright notices to everything
lirazsiri authored
4 # This file is part of TKLBAM (TurnKey Linux BAckup and Migration).
767facb @lirazsiri cleanup whitespace
lirazsiri authored
5 #
e34925a @lirazsiri free software => open source software
lirazsiri authored
6 # TKLBAM is open source software; you can redistribute it and/or
0c11ee9 @lirazsiri added copyright notices to everything
lirazsiri authored
7 # modify it under the terms of the GNU General Public License as
8 # published by the Free Software Foundation; either version 3 of
9 # the License, or (at your option) any later version.
767facb @lirazsiri cleanup whitespace
lirazsiri authored
10 #
8250707 @lirazsiri refactored out duplicity execution to a separate module
lirazsiri authored
11 import os
0a7f0ca @lirazsiri patched tklbam to use tklbam-duplicity and tklbam-python-boto
lirazsiri authored
12 from os.path import *
13
7765409 @lirazsiri cleanup before backing up (disables checkpoint/restore)
lirazsiri authored
14 import sys
8250707 @lirazsiri refactored out duplicity execution to a separate module
lirazsiri authored
15
16 from subprocess import *
17
0a7f0ca @lirazsiri patched tklbam to use tklbam-duplicity and tklbam-python-boto
lirazsiri authored
18 def _find_duplicity_pylib(path):
19 if not isdir(path):
20 return None
21
22 for fpath, dnames, fnames in os.walk(path):
23 if 'duplicity' in dnames:
24 return fpath
25
26 return None
27
28 PATH_DEPS = os.environ.get('TKLBAM_DEPS', '/usr/lib/tklbam/deps')
29 PATH_DEPS_BIN = join(PATH_DEPS, "bin")
30 PATH_DEPS_PYLIB = _find_duplicity_pylib(PATH_DEPS)
31
8250707 @lirazsiri refactored out duplicity execution to a separate module
lirazsiri authored
32 class Error(Exception):
33 pass
34
35 class Command:
1b0c7d1 @lirazsiri improved duplicity.Command interface
lirazsiri authored
36 def __init__(self, *args):
37 """Duplicity command. The first member of args can be a an array of tuple arguments"""
38
39 if isinstance(args[0], list):
40 opts = args[0]
41 args = args[1:]
42 else:
43 opts = []
44
8250707 @lirazsiri refactored out duplicity execution to a separate module
lirazsiri authored
45 if not args:
46 raise Error("no arguments!")
47
48 opts += [ ('archive-dir', '/var/cache/duplicity') ]
49
50 opts = [ "--%s=%s" % (key, val) for key, val in opts ]
51 self.command = ["duplicity"] + opts + list(args)
52
1b0f87c @lirazsiri tklbam-backup --debug command
lirazsiri authored
53 def run(self, passphrase, creds=None, debug=False):
7765409 @lirazsiri cleanup before backing up (disables checkpoint/restore)
lirazsiri authored
54 sys.stdout.flush()
55
2cf23fb @lirazsiri pass S3 credentials to boto + refactored credentials into a class
lirazsiri authored
56 if creds:
57 os.environ['AWS_ACCESS_KEY_ID'] = creds.accesskey
58 os.environ['AWS_SECRET_ACCESS_KEY'] = creds.secretkey
f43537a @lirazsiri tklbam now depends on new tklbam-python-boto version
lirazsiri authored
59 os.environ['X_AMZ_SECURITY_TOKEN'] = ",".join([creds.producttoken, creds.usertoken])
2cf23fb @lirazsiri pass S3 credentials to boto + refactored credentials into a class
lirazsiri authored
60
0a7f0ca @lirazsiri patched tklbam to use tklbam-duplicity and tklbam-python-boto
lirazsiri authored
61 if PATH_DEPS_BIN not in os.environ['PATH'].split(':'):
62 os.environ['PATH'] = PATH_DEPS_BIN + ':' + os.environ['PATH']
63
64 if PATH_DEPS_PYLIB:
65 os.environ['PYTHONPATH'] = PATH_DEPS_PYLIB
66
8250707 @lirazsiri refactored out duplicity execution to a separate module
lirazsiri authored
67 os.environ['PASSPHRASE'] = passphrase
f43537a @lirazsiri tklbam now depends on new tklbam-python-boto version
lirazsiri authored
68
1b0f87c @lirazsiri tklbam-backup --debug command
lirazsiri authored
69 if debug:
70 import executil
71 executil.system(os.environ.get("SHELL", "/bin/bash"))
72
8250707 @lirazsiri refactored out duplicity execution to a separate module
lirazsiri authored
73 child = Popen(self.command)
74 del os.environ['PASSPHRASE']
75
76 exitcode = child.wait()
77 if exitcode != 0:
78 raise Error("non-zero exitcode (%d) from backup command: %s" % (exitcode, str(self)))
767facb @lirazsiri cleanup whitespace
lirazsiri authored
79
8250707 @lirazsiri refactored out duplicity execution to a separate module
lirazsiri authored
80 def __str__(self):
81 return " ".join(self.command)
Something went wrong with that request. Please try again.