-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup-deb-dr
executable file
·53 lines (46 loc) · 1.83 KB
/
backup-deb-dr
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
53
#!/usr/bin/env python
"""
This file wil be the main executable to start the backup of the
current system.
This executable will create all that is needed for the restore
"""
# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
import dpkg
import restore
import logging
from optparse import OptionParser
import sys
parser = OptionParser()
parser.add_option('-d', '--debug', dest='debuglevel', default='DEBUG',
type='string',
help="The debuglevel for logging")
parser.add_option('-l', '--logfile', dest='logfile', type='string',
default='backup-deb-dr.log',
help="The debuglevel for logging")
parser.add_option('-f', '--file', dest='filename', type='string',
default='/tmp/restore',
help="The filename of the resulting script")
(option, args) = parser.parse_args()
# Setup the runtime (default) configuration settings
logging.basicConfig(filename=option.logfile)
log = logging.getLogger(sys.argv[0])
output = option.filename
numeric_level = getattr(logging, option.debuglevel.upper(), None)
if not isinstance(numeric_level, int):
raise ValueError('Invalid log level: %s' % option.debuglevel)
# Here we start with the real work
log.setLevel(numeric_level)
dpkg = dpkg.Dpkg(numeric_level)
dpkg_list = dpkg.make_dpkg_listing()
log.info("Obtained a list of packages")
config_files = list()
for pkg in dpkg_list:
log.debug("Processiong package (%s)" % (pkg))
cfg_file = dpkg.find_altered_config(pkg)
config_files.extend(cfg_file)
log.info("Starting with the restore file(s) creation")
restore = restore.Restore(numeric_level)
restore.add_files(config_files)
restore.add_packages(dpkg_list)
restore.create_file(output) # make cli based with default
log.info("Restore files created with startname: %s" % (output))