summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2009-12-03 17:24:46 +0200
committerLars Wirzenius <liw@liw.fi>2009-12-03 17:24:46 +0200
commita062a445b8f4569b2bda85fad548d0efd31fdbe3 (patch)
tree1ad776e7cabbf7b9c4eb3f235799644f293f786a
parenta6edc32faf628c5cab28d8a4388f507be8a9d3d0 (diff)
downloadobnam-a062a445b8f4569b2bda85fad548d0efd31fdbe3.tar.gz
Added a rudimentary beginnings of a backup plugin.
-rw-r--r--obnamlib/plugins/backup_plugin.py67
-rw-r--r--without-tests1
2 files changed, 68 insertions, 0 deletions
diff --git a/obnamlib/plugins/backup_plugin.py b/obnamlib/plugins/backup_plugin.py
new file mode 100644
index 00000000..03becbc8
--- /dev/null
+++ b/obnamlib/plugins/backup_plugin.py
@@ -0,0 +1,67 @@
+# Copyright (C) 2009 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/>.
+
+
+import logging
+import os
+
+import obnamlib
+
+
+# Implementation plan:
+# 1. Back up everything, every time.
+# 2. Back up only changed files, but completely.
+# 3. Back up changes using rsync + looking up of chunks via checksums.
+
+
+
+class BackupPlugin(obnamlib.ObnamPlugin):
+
+ def enable(self):
+ self.app.register_command('backup', self.backup)
+ self.app.config.new_list(['root'], 'what to backup')
+
+ def backup(self, args):
+ roots = self.app.config['root'] + args
+ self.app.hooks.call('status', 'roots %s' % roots)
+ fsf = obnamlib.VfsFactory()
+ storefs = fsf.new(self.app.config['store'])
+ self.store = obnamlib.Store(storefs)
+ for root in roots:
+ self.fs = fsf.new(root)
+ self.fs.connect()
+ self.backup_something(root)
+ self.fs.close()
+
+ def backup_something(self, root):
+ if self.fs.isdir(root):
+ self.backup_dir(root)
+ else:
+ self.backup_file(root)
+
+ def backup_file(self, root):
+ self.app.hooks.call('status', 'backing up file %s' % root)
+ stat_result = self.fs.lstat(root)
+ fileobj = obnamlib.File(basename=os.path.basename(root),
+ metadata=stat_result)
+ self.store.put_object(fileobj)
+ return fileobj
+
+ def backup_dir(self, root):
+ self.app.hooks.call('status', 'backing up dir %s' % root)
+ for basename in self.fs.listdir(root):
+ fullname = os.path.join(root, basename)
+ self.backup_something(fullname)
+
diff --git a/without-tests b/without-tests
index 3228116b..751e8e80 100644
--- a/without-tests
+++ b/without-tests
@@ -7,6 +7,7 @@
./obnamlib/objs.py
./obnamlib/store.py
./obnamlib/plugins/foo_plugin.py
+./obnamlib/plugins/backup_plugin.py
./obnamlib/plugins/terminal_status_plugin.py
./test-plugins/hello_plugin.py
./test-plugins/oldhello_plugin.py