From 22fedd5bf837233fc59340634f6cd7e81717a2d1 Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Fri, 3 Dec 2010 01:25:49 +0100 Subject: Initial bcfg2-admin backup part (cherry picked from commit a5f0c8b9936eb55283b3a2bb03e048842c773b45) --- src/lib/Server/Admin/Backup.py | 47 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/lib/Server/Admin/Backup.py (limited to 'src/lib/Server/Admin/Backup.py') diff --git a/src/lib/Server/Admin/Backup.py b/src/lib/Server/Admin/Backup.py new file mode 100644 index 000000000..583f0329c --- /dev/null +++ b/src/lib/Server/Admin/Backup.py @@ -0,0 +1,47 @@ +import glob +import sys +import time +import tarfile +import Bcfg2.Server.Admin +import Bcfg2.Options + +class Backup(Bcfg2.Server.Admin.MetadataCore): + __shorthelp__ = "Make a backup of the Bcfg2 repository." + __longhelp__ = (__shorthelp__ + "\n\nbcfg2-admin backup start" + "\n\nbcfg2-admin backup restore") + __usage__ = ("bcfg2-admin backup [start|restore]") + + def __init__(self, configfile): + Bcfg2.Server.Admin.MetadataCore.__init__(self, configfile, + self.__usage__) + + def __call__(self, args): + Bcfg2.Server.Admin.MetadataCore.__call__(self, args) + # Get Bcfg2 repo directory + opts = {'repo': Bcfg2.Options.SERVER_REPOSITORY} + setup = Bcfg2.Options.OptionParser(opts) + setup.parse(sys.argv[1:]) + repo = setup['repo'] + + if len(args) == 0: + self.errExit("No argument specified.\n" + "Please see bcfg2-admin backup help for usage.") + if args[0] == 'start': + timestamp = time.strftime('%Y%m%d%H%M%S') + format = 'gz' + mode = 'w:' + format + filename = timestamp + '.tar' + '.' + format + out = tarfile.open(filename, mode=mode) + content = os.listdir(os.getcwd()) + for item in content: + out.add(item) + out.close() + print "Archive %s was stored.\nLocation: %s" % (filename, datastore) + + elif args[0] == 'restore': + print 'Not implemented yet' + + else: + print "No command specified" + raise SystemExit(1) + -- cgit v1.2.3-1-g7c22 From 1d8a9780d38b095ac2e67e3aeb5e436c756b719a Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Fri, 3 Dec 2010 01:52:34 +0100 Subject: Fixed backup location (cherry picked from commit c9eec98340168b1e9e3f4877b15b681855ee696b) --- src/lib/Server/Admin/Backup.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/lib/Server/Admin/Backup.py') diff --git a/src/lib/Server/Admin/Backup.py b/src/lib/Server/Admin/Backup.py index 583f0329c..f150b9cf0 100644 --- a/src/lib/Server/Admin/Backup.py +++ b/src/lib/Server/Admin/Backup.py @@ -1,4 +1,5 @@ import glob +import os import sys import time import tarfile @@ -21,7 +22,7 @@ class Backup(Bcfg2.Server.Admin.MetadataCore): opts = {'repo': Bcfg2.Options.SERVER_REPOSITORY} setup = Bcfg2.Options.OptionParser(opts) setup.parse(sys.argv[1:]) - repo = setup['repo'] + self.datastore = setup['repo'] if len(args) == 0: self.errExit("No argument specified.\n" @@ -31,12 +32,12 @@ class Backup(Bcfg2.Server.Admin.MetadataCore): format = 'gz' mode = 'w:' + format filename = timestamp + '.tar' + '.' + format - out = tarfile.open(filename, mode=mode) - content = os.listdir(os.getcwd()) + out = tarfile.open(self.datastore + '/' + filename, mode=mode) + content = os.listdir(self.datastore) for item in content: out.add(item) out.close() - print "Archive %s was stored.\nLocation: %s" % (filename, datastore) + print "Archive %s was stored.\nLocation: %s" % (filename, self.datastore) elif args[0] == 'restore': print 'Not implemented yet' -- cgit v1.2.3-1-g7c22 From 8f96008ca5d3a567bed009dd0401007aa6cb9223 Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Sun, 5 Dec 2010 21:50:18 +0100 Subject: Backup part reworked (cherry picked from commit 94e4f622b4dee6b33983a17313c0ef5a71c93f2e) --- src/lib/Server/Admin/Backup.py | 38 +++++++++++--------------------------- 1 file changed, 11 insertions(+), 27 deletions(-) (limited to 'src/lib/Server/Admin/Backup.py') diff --git a/src/lib/Server/Admin/Backup.py b/src/lib/Server/Admin/Backup.py index f150b9cf0..27a7fd8c8 100644 --- a/src/lib/Server/Admin/Backup.py +++ b/src/lib/Server/Admin/Backup.py @@ -1,4 +1,3 @@ -import glob import os import sys import time @@ -8,9 +7,9 @@ import Bcfg2.Options class Backup(Bcfg2.Server.Admin.MetadataCore): __shorthelp__ = "Make a backup of the Bcfg2 repository." - __longhelp__ = (__shorthelp__ + "\n\nbcfg2-admin backup start" - "\n\nbcfg2-admin backup restore") - __usage__ = ("bcfg2-admin backup [start|restore]") + __longhelp__ = (__shorthelp__ + "\n\nbcfg2-admin backup") + #"\n\nbcfg2-admin backup restore") + __usage__ = ("bcfg2-admin backup") def __init__(self, configfile): Bcfg2.Server.Admin.MetadataCore.__init__(self, configfile, @@ -23,26 +22,11 @@ class Backup(Bcfg2.Server.Admin.MetadataCore): setup = Bcfg2.Options.OptionParser(opts) setup.parse(sys.argv[1:]) self.datastore = setup['repo'] - - if len(args) == 0: - self.errExit("No argument specified.\n" - "Please see bcfg2-admin backup help for usage.") - if args[0] == 'start': - timestamp = time.strftime('%Y%m%d%H%M%S') - format = 'gz' - mode = 'w:' + format - filename = timestamp + '.tar' + '.' + format - out = tarfile.open(self.datastore + '/' + filename, mode=mode) - content = os.listdir(self.datastore) - for item in content: - out.add(item) - out.close() - print "Archive %s was stored.\nLocation: %s" % (filename, self.datastore) - - elif args[0] == 'restore': - print 'Not implemented yet' - - else: - print "No command specified" - raise SystemExit(1) - + timestamp = time.strftime('%Y%m%d%H%M%S') + format = 'gz' + mode = 'w:' + format + filename = timestamp + '.tar' + '.' + format + out = tarfile.open(self.datastore + '/' + filename, mode=mode) + out.add(self.datastore, os.path.basename(self.datastore)) + out.close() + print "Archive %s was stored under %s" % (filename, self.datastore) -- cgit v1.2.3-1-g7c22