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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
#!/usr/bin/python
#
# Copyright (C) 2006, 2007, 2008 Lars Wirzenius <liw@iki.fi>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
"""A backup program"""
import logging
import sys
import traceback
import obnamlib
def main():
try:
context = obnamlib.context.Context()
args = obnamlib.config.parse_options(context.config, sys.argv[1:])
context.map.max = context.config.getint("backup", "max-mappings")
context.contmap.max = context.config.getint("backup", "max-mappings")
context.cache = obnamlib.cache.Cache(context.config)
context.be = obnamlib.backend.init(context.config, context.cache)
context.be.set_progress_reporter(context.progress)
app = obnamlib.Application(context)
obnamlib.log.setup(context.config)
logging.info("%s %s starting up" % (obnamlib.NAME, obnamlib.VERSION))
try:
factory = obnamlib.OperationFactory(app)
oper = factory.get_operation(args)
oper.do_it(args[1:])
logging.info("Store I/O: %d kB read, %d kB written" %
(context.be.get_bytes_read() / 1024,
context.be.get_bytes_written() / 1024))
logging.info("Obnam finishing")
context.progress.final_report()
if app.get_store():
app.get_store().close()
except KeyboardInterrupt:
logging.warning("Obnam interrupted by Control-C, aborting.")
logging.warning("Note that backup has not been completed.")
sys.stderr.write("Obnam interrupted by Control-C, aborting.\n")
sys.stderr.write("Note that backup has not been completed.\n")
if app.get_store():
app.get_store().close()
sys.exit(1)
except obnamlib.ObnamException, e:
logging.error("%s" % str(e))
sys.stderr.write("%s\n" % str(e))
if app.get_store():
app.get_store().close()
sys.exit(1)
except SystemExit:
sys.exit(1)
except BaseException, e:
logging.error("%s" % repr(e))
logging.error("%s" % traceback.format_exc())
sys.stderr.write("%s\n" % repr(e))
sys.stderr.write("%s\n" % traceback.format_exc())
if app.get_store():
app.get_store().close()
sys.exit(1)
if __name__ == "__main__":
main()
|