1 # Cumulus: Smart Filesystem Backup to Dumb Servers
3 # Copyright (C) 2012 Google Inc.
4 # Written by Michael Vrable <mvrable@cs.ucsd.edu>
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with this program; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 """The Python-based Cumulus script.
22 This implements maintenance functions and is a wrapper around the C++
23 cumulus-backup program.
30 from cumulus import cmd_util
31 from cumulus import config
36 def prune_backups(backup_config, scheme):
37 store = cumulus.LowlevelDataStore(backup_config.get_global("dest"))
38 snapshot_re = re.compile(r"^(.*)-(.*)$")
39 retention = backup_config.get_retention_for_scheme(scheme)
40 expired_snapshots = []
41 for snapshot in sorted(store.list_snapshots()):
42 m = snapshot_re.match(snapshot)
43 if m.group(1) != scheme: continue
44 timestamp = m.group(2)
45 keep = retention.consider_snapshot(timestamp)
47 expired_snapshots.append(snapshot)
48 # The most recent snapshot is never removed.
49 if expired_snapshots: expired_snapshots.pop()
50 print expired_snapshots
52 # TODO: Clean up the expiration part...
53 for snapshot in expired_snapshots:
54 store.store.delete("snapshot", "snapshot-%s.lbs" % snapshot)
56 print "Collecting garbage..."
57 options = FakeOptions()
58 options.store = backup_config.get_global("dest")
59 options.dry_run = False
60 cmd_util.options = options
61 cmd_util.cmd_garbage_collect([])
64 backup_config = config.CumulusConfig(argv[1])
65 for scheme in backup_config.backup_schemes():
67 prune_backups(backup_config, scheme)
69 if __name__ == "__main__":