-# Cumulus: Smart Filesystem Backup to Dumb Servers
-#
-# Copyright (C) 2012 Google Inc.
-# Written by Michael Vrable <mvrable@cs.ucsd.edu>
+# 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
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):
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):
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])