summaryrefslogtreecommitdiff
path: root/create-reference-repo
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2013-12-28 21:10:25 +0000
committerLars Wirzenius <liw@liw.fi>2013-12-28 21:10:25 +0000
commit2d0d4f8dd8642391d98f5da4b521dc95b0c19e63 (patch)
tree30f75297d3a3558953b7d8f60c6043adb30f78ee /create-reference-repo
parent6b791218de91e9e1963301b820bd5ddb92d06486 (diff)
downloadobnam-2d0d4f8dd8642391d98f5da4b521dc95b0c19e63.tar.gz
Add script to create a reference repository
Diffstat (limited to 'create-reference-repo')
-rwxr-xr-xcreate-reference-repo109
1 files changed, 109 insertions, 0 deletions
diff --git a/create-reference-repo b/create-reference-repo
new file mode 100755
index 00000000..85eb514c
--- /dev/null
+++ b/create-reference-repo
@@ -0,0 +1,109 @@
+#!/usr/bin/python
+# Copyright 2013 Lars Wirzenius
+#
+# 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 3 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, see <http://www.gnu.org/licenses/>.
+#
+# =*= License: GPL-3+ =*=
+
+
+description = '''\
+Create a reference repository for an Obnam version.
+
+Create a tar file containing an Obnam backup repository and some
+summain(1) manifests. The repository contains two backup generations,
+of test live data generated by ./mkfunnyfarm. The backups are made
+using encryption and compression, using the test PGP keys in
+./test-gpghome.
+
+The point of this is to archive the tar file and use it to test that
+future versions of Obnam can restore the data and otherwise use the
+repository.
+
+Only one command line argument: path to the Obnam executable.
+
+'''
+
+
+import cliapp
+import os
+import shutil
+import tarfile
+import tempfile
+
+
+class CreateReferenceRepository(cliapp.Application):
+
+ def add_settings(self):
+ self.settings.string(
+ ['obnam'],
+ 'which obnam to execute (default: %default)',
+ metavar='CMD',
+ default='./obnam')
+
+ def process_args(self, args):
+ if args:
+ raise cliapp.AppException('Wrong command line args')
+
+ tempdir = tempfile.mkdtemp()
+ live_dir = os.path.join(tempdir, 'data')
+ repo_dir = os.path.join(tempdir, 'repo')
+
+ # First generation.
+ self.create_live_data(live_dir)
+ self.create_manifest(live_dir, os.path.join(tempdir, 'manifest-1'))
+ self.backup(live_dir, repo_dir)
+
+ # Second generation.
+ self.modify_live_data(live_dir)
+ self.create_manifest(live_dir, os.path.join(tempdir, 'manifest-2'))
+ self.backup(live_dir, repo_dir)
+
+ # Remove the live data. Everything will be tarred up.
+ shutil.rmtree(live_dir)
+
+ # Tar up.
+ self.create_tar_file(tempdir)
+
+ def create_live_data(self, dirname):
+ cliapp.runcmd(['./mkfunnyfarm', dirname])
+
+ def modify_live_data(self, dirname):
+ filename = os.path.join(dirname, 'new-file.txt')
+ with open(filename, 'w') as f:
+ f.write('This file created for 2nd generation.\n')
+
+ def create_manifest(self, dirname, manifest_name):
+ cliapp.runcmd(
+ ['summain', '--exclude=Ino', '--exclude=Dev', '--exclude=Uid',
+ '--exclude=Username', '--exclude=Gid', '--exclude=Group',
+ '-r', '--output', manifest_name, dirname])
+
+ def backup(self, live_dir, repo_dir):
+ env = dict(os.environ)
+ env['GNUPGHOME'] = 'test-gpghome'
+ # The encryption key is the one in test-gpghome.
+ cliapp.runcmd(
+ [self.settings['obnam'], '--no-default-config', '--quiet',
+ '--weak-random', '--encrypt-with=3B1802F81B321347',
+ '--compress-with=deflate', '-r', repo_dir, 'backup', live_dir],
+ env=env)
+
+ def create_tar_file(self, tempdir):
+ with tarfile.TarFile(fileobj=self.output, mode='w') as f:
+ for basename in os.listdir(tempdir):
+ pathname = os.path.join(tempdir, basename)
+ f.add(pathname, arcname=basename)
+
+
+CreateReferenceRepository(description=description).run()