summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFabian Affolter <fabian@bernewireless.net>2010-12-03 01:25:49 +0100
committerSol Jerome <sol.jerome@gmail.com>2010-12-07 20:21:45 -0600
commit22fedd5bf837233fc59340634f6cd7e81717a2d1 (patch)
treec7c91faab3529e5eddecd537036e4a76cc83fc9e /src
parent0cff753190c235a9ce65a920730d715a5e4a8ed4 (diff)
downloadbcfg2-22fedd5bf837233fc59340634f6cd7e81717a2d1.tar.gz
bcfg2-22fedd5bf837233fc59340634f6cd7e81717a2d1.tar.bz2
bcfg2-22fedd5bf837233fc59340634f6cd7e81717a2d1.zip
Initial bcfg2-admin backup part
(cherry picked from commit a5f0c8b9936eb55283b3a2bb03e048842c773b45)
Diffstat (limited to 'src')
-rw-r--r--src/lib/Server/Admin/Backup.py47
-rw-r--r--src/lib/Server/Admin/__init__.py2
2 files changed, 48 insertions, 1 deletions
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)
+
diff --git a/src/lib/Server/Admin/__init__.py b/src/lib/Server/Admin/__init__.py
index 3a088b2fb..bb5c41895 100644
--- a/src/lib/Server/Admin/__init__.py
+++ b/src/lib/Server/Admin/__init__.py
@@ -2,7 +2,7 @@ __revision__ = '$Revision$'
__all__ = ['Mode', 'Client', 'Compare', 'Init', 'Minestruct', 'Perf',
'Pull', 'Query', 'Reports', 'Snapshots', 'Tidy', 'Viz',
- 'Xcmd', 'Group']
+ 'Xcmd', 'Group', 'Backup']
import ConfigParser
import logging