X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=python%2Fcumulus%2Fretention.py;h=e447b541ad277b1f435b2393ef43a546e6fef613;hb=a5f66616b1ec0c38328ad5131bf1c889ccc43659;hp=e89263a9c6bf7b5387641bf34e52e3458a6457e3;hpb=7357b690367c22d35edf3f375bd4a91ccdf014c0;p=cumulus.git diff --git a/python/cumulus/retention.py b/python/cumulus/retention.py index e89263a..e447b54 100644 --- a/python/cumulus/retention.py +++ b/python/cumulus/retention.py @@ -1,7 +1,6 @@ -# Cumulus: Smart Filesystem Backup to Dumb Servers -# -# Copyright (C) 2012 Google Inc. -# Written by Michael Vrable +# Cumulus: Efficient Filesystem Backup to the Cloud +# Copyright (C) 2012 The Cumulus Developers +# See the AUTHORS file for a list of contributors. # # 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 @@ -103,10 +102,12 @@ class RetentionEngine(object): def add_policy(self, backup_class, retention_period): self._policies[backup_class] = retention_period - self._last_snapshots[backup_class] = (None, None) + self._last_snapshots[backup_class] = (None, None, False) @staticmethod def parse_timestamp(s): + if isinstance(s, datetime.datetime): + return s return datetime.datetime.strptime(s, TIMESTAMP_FORMAT) def consider_snapshot(self, snapshot): @@ -131,13 +132,15 @@ class RetentionEngine(object): self._labels = set() retain = False - for (backup_class, retention_period) in self._policies.iteritems(): + for (backup_class, retention_period) in self._policies.items(): partition = _backup_classes[backup_class](timestamp_policy) last_snapshot = self._last_snapshots[backup_class] if self._last_snapshots[backup_class][0] != partition: - self._last_snapshots[backup_class] = (partition, snapshot) self._labels.add(backup_class) - if snapshot_age < retention_period: retain = True + retain_label = snapshot_age < retention_period + self._last_snapshots[backup_class] = (partition, snapshot, + retain_label) + if retain_label: retain = True return retain def last_labels(self): @@ -149,4 +152,5 @@ class RetentionEngine(object): def last_snapshots(self): """Returns the most recent snapshot in each backup class.""" - return dict((k, v[1]) for (k, v) in self._last_snapshots.iteritems()) + return dict((k, v[1]) for (k, v) + in self._last_snapshots.items() if v[2])