X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=python%2Fcumulus%2Fretention.py;h=b0e007887f6e8cde917f8bf40efde9d09ac4161b;hb=ad1381b6da02a65ebadfc2f466e9bf6ab9086229;hp=e89263a9c6bf7b5387641bf34e52e3458a6457e3;hpb=7357b690367c22d35edf3f375bd4a91ccdf014c0;p=cumulus.git diff --git a/python/cumulus/retention.py b/python/cumulus/retention.py index e89263a..b0e0078 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): @@ -135,9 +136,11 @@ class RetentionEngine(object): 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.iteritems() if v[2])