-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackup.py
executable file
·52 lines (40 loc) · 1.42 KB
/
backup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python
"""
Backup using backup_to_s3.py and python-boto
"""
import sys
from backup_to_s3 import backup_to_s3
from getconf import getconf, findconfs
def _backup_to_s3(access_key, secret_access_key, bucket, directories = {}, commands = {}, files = {}):
print " > " + bucket
print " > directories"
for d,dd in directories.items(): print " > %s : %s" % (d,dd)
print " > commands"
for d,dd in commands.items(): print " > %s : %s" % (d,dd)
print " > files"
for d,dd in files.items(): print " > %s : %s" % (d,dd)
keys = getconf('INIT', subconf='keys')
confs = findconfs(excluding=('INIT',))
# Optional command-line filter
try: confs = [c for c in confs if c == sys.argv[1] or sys.argv[1] == 'ALL']
except IndexError: pass
for conf_name in confs:
conf = getconf(conf_name)
label = conf['META'].get('label', "Unnamed backup %s" % conf_name)
print "Starting backup: '%s'" % label
args = {
'access_key': keys['access'],
'secret_access_key': keys['secret'],
'bucket': conf['META']['bucket'],
'directories': conf.get('directories', {}),
'commands': conf.get('commands', {}),
'files': conf.get('files', {}),
}
_backup_to_s3(**args)
if len(sys.argv) == 3 and sys.argv[2] == "go":
backup_to_s3(**args)
else:
print "DRY RUN"
print "Finishing backup: '%s'\n" % label
if not confs:
print "No conf files: nothing to do."