]> andersk Git - sql.git/blame - libexec/backup-policy.py
backups: keep less monthlys
[sql.git] / libexec / backup-policy.py
CommitLineData
562fda3a
JP
1#!/usr/bin/python
2
3import os, re, sys
4from time import strptime
5from glob import glob
6
7PATH = os.path.abspath(sys.argv[1])
8backups = glob('%s/weekly/*.gz' % PATH)
9backups.sort()
10backups.reverse()
11backups = [[x, re.match('.*(\d\d\d\d-\d\d-\d\d).*', x)] for x in backups]
12backups = [[x[0], strptime(x[1].groups()[0], '%Y-%m-%d')] for x in backups]
13
cd14464c
JP
14keep = backups[:2]
15backups = backups[2:]
562fda3a
JP
16monthlys = {}
17for x in backups:
18 month = (x[1].tm_year, x[1].tm_mon)
19 if month not in monthlys:
20 monthlys[month] = x
cd14464c 21 if len(monthlys) > 3:
562fda3a
JP
22 break
23keep.extend(monthlys.values())
24
25for x in backups:
26 if not x in keep:
27 print 'rm %s' % x[0]
28 else:
29 print '# keeping %s' % x[0]
This page took 0.255677 seconds and 5 git commands to generate.