diff options
author | Lars Wirzenius <liw@liw.fi> | 2010-07-04 11:57:42 +1200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2010-07-04 11:57:42 +1200 |
commit | 44fd445bb0039714c379b526076a98ac4ddd7256 (patch) | |
tree | e31db7fa944ae1e9bd1c040c3634552fed74bd23 | |
parent | 5f1dde68e0ddebf8158c95e7cc895609039cbcde (diff) | |
download | obnam-44fd445bb0039714c379b526076a98ac4ddd7256.tar.gz |
Mark checkpoint generations as such, and report them in generation listing.
-rw-r--r-- | obnamlib/plugins/backup_plugin.py | 2 | ||||
-rw-r--r-- | obnamlib/plugins/show_plugin.py | 10 | ||||
-rw-r--r-- | obnamlib/store.py | 20 | ||||
-rw-r--r-- | obnamlib/store_tests.py | 16 |
4 files changed, 44 insertions, 4 deletions
diff --git a/obnamlib/plugins/backup_plugin.py b/obnamlib/plugins/backup_plugin.py index d1ad0759..eeda1199 100644 --- a/obnamlib/plugins/backup_plugin.py +++ b/obnamlib/plugins/backup_plugin.py @@ -88,7 +88,7 @@ class BackupPlugin(obnamlib.ObnamPlugin): if storefs.written >= self.app.config['checkpoint']: logging.debug('Making checkpoint') self.backup_parents('.') - self.store.commit_host() + self.store.commit_host(checkpoint=True) self.store.lock_host(hostname) self.store.start_generation() storefs.written = 0 diff --git a/obnamlib/plugins/show_plugin.py b/obnamlib/plugins/show_plugin.py index 29c1c29f..05cc6088 100644 --- a/obnamlib/plugins/show_plugin.py +++ b/obnamlib/plugins/show_plugin.py @@ -52,10 +52,16 @@ class ShowPlugin(obnamlib.ObnamPlugin): self.open_store() for gen in self.store.list_generations(): start, end = self.store.get_generation_times(gen) - sys.stdout.write('%s\t%s .. %s\n' % + is_checkpoint = self.store.get_is_checkpoint(gen) + if is_checkpoint: + checkpoint = ' (checkpoint)' + else: + checkpoint = '' + sys.stdout.write('%s\t%s .. %s%s\n' % (gen, self.format_time(start), - self.format_time(end))) + self.format_time(end), + checkpoint)) def ls(self, args): self.open_store() diff --git a/obnamlib/store.py b/obnamlib/store.py index e94e9e97..5696f291 100644 --- a/obnamlib/store.py +++ b/obnamlib/store.py @@ -252,6 +252,7 @@ class GenerationStore(StoreTree): GEN_META_ID = 0 GEN_META_STARTED = 1 GEN_META_ENDED = 2 + GEN_META_IS_CHECKPOINT = 3 FILE_NAME = 0 FILE_METADATA = 1 @@ -348,6 +349,16 @@ class GenerationStore(StoreTree): self._insert_int(self.curgen, self.genkey(self.GEN_META_ID), gen_id) self._insert_int(self.curgen, self.genkey(self.GEN_META_STARTED), now) + def set_current_generation_is_checkpoint(self, is_checkpoint): + value = 1 if is_checkpoint else 0 + key = self.genkey(self.GEN_META_IS_CHECKPOINT) + self._insert_int(self.curgen, key, value) + + def get_is_checkpoint(self, genid): + tree = self.find_generation(genid) + key = self.genkey(self.GEN_META_IS_CHECKPOINT) + return self._lookup_int(tree, key) + def remove_generation(self, genid): tree = self.find_generation(genid) if tree == self.curgen: @@ -750,8 +761,10 @@ class Store(object): self.current_host = None @require_host_lock - def commit_host(self): + def commit_host(self, checkpoint=False): '''Commit changes to and unlock currently locked host.''' + if self.new_generation: + self.genstore.set_current_generation_is_checkpoint(checkpoint) self.added_generations = [] for genid in self.removed_generations: self._really_remove_generation(genid) @@ -774,6 +787,11 @@ class Store(object): '''List existing generations for currently open host.''' return self.genstore.list_generations() + @require_open_host + def get_is_checkpoint(self, genid): + '''Is a generation a checkpoint one?''' + return self.genstore.get_is_checkpoint(genid) + @require_host_lock def start_generation(self): '''Start a new generation. diff --git a/obnamlib/store_tests.py b/obnamlib/store_tests.py index 7b04ee07..7ac5c45c 100644 --- a/obnamlib/store_tests.py +++ b/obnamlib/store_tests.py @@ -282,6 +282,22 @@ class StoreHostTests(unittest.TestCase): self.store.commit_host() self.assertFalse(self.store.got_host_lock) + def test_commit_does_not_mark_as_checkpoint_by_default(self): + self.store.lock_host('hostname') + self.store.start_generation() + genid = self.store.new_generation + self.store.commit_host() + self.store.open_host('hostname') + self.assertFalse(self.store.get_is_checkpoint(genid)) + + def test_commit_marks_as_checkpoint_when_requested(self): + self.store.lock_host('hostname') + self.store.start_generation() + genid = self.store.new_generation + self.store.commit_host(checkpoint=True) + self.store.open_host('hostname') + self.assert_(self.store.get_is_checkpoint(genid)) + def test_commit_host_without_lock_fails(self): self.assertRaises(obnamlib.LockFail, self.store.commit_host) |