diff --git a/backup.py b/backup.py index 6a1d55d..5758e06 100755 --- a/backup.py +++ b/backup.py @@ -46,7 +46,15 @@ loglvls = {'critical': logging.CRITICAL, dflt_ns = 'http://git.root2.io/r00t2/borgextend/' # In code, replace "day" with "daily" when constructing command. -policyperiods = ('Second', 'Minute', 'Hour', 'Day', 'Week', 'Month', 'Year') +policyperiods = ( + ('seconds', 'secondly'), + ('minutes', 'minutely'), + ('hours', 'hourly'), + ('days', 'daily'), + ('weeks', 'weekly'), + ('months', 'monthly'), + ('years', 'yearly'), + ) ### THE GUTS ### class Backup(object): @@ -170,14 +178,13 @@ class Backup(object): r['retention']['last'] = isodate.parse_duration(keepWithin.text) keepLast = repo.find('{0}keepLast'.format(self.ns)) if keepLast is not None: - for e in policyperiods: - k = e.lower() - policy = keepLast.find('{0}per{1}'.format(self.ns, e)) + for e, _ in policyperiods: + policy = keepLast.find('{0}{1}'.format(self.ns, e)) if policy is not None: if 'retention' not in r.keys(): r['retention'] = {} # This is safe. We validate the config. - r['retention'][k] = int(policy.text) + r['retention'][e] = int(policy.text) repos.append(r) return(repos) self.logger.debug('VARS (before args cleanup): {0}'.format(vars(self))) @@ -514,12 +521,9 @@ class Backup(object): retentionSeconds = repo['retention'].totimedelta(datetime.datetime.now()).total_seconds() _cmd.extend(['--keep-within', '{0}H'.format(retentionSeconds / 60)]) # keepLast - for e in policyperiods: - if repo['retention'].get(e.lower()) is not None: - a = e.lower() + 'ly' - if e.lower() == 'day': - a = 'daily' - _cmd.extend(['--keep-{0}'.format(a), repo['retention'][e.lower()]]) + for e, a in policyperiods: + if repo['retention'].get(e, 0) is not 0: + _cmd.extend(['--keep-{0}'.format(a), repo['retention'][e]]) if self.repos[server]['remote'].lower()[0] in ('1', 't'): repo_tgt = '{0}@{1}'.format(_user, server) else: diff --git a/config.xsd b/config.xsd index f9cc0e1..b1472ea 100644 --- a/config.xsd +++ b/config.xsd @@ -64,13 +64,13 @@ - - - - - - - + + + + + + + diff --git a/sample.config.xml b/sample.config.xml index 86ce93d..e33964a 100644 --- a/sample.config.xml +++ b/sample.config.xml @@ -41,12 +41,12 @@ P1MT2M30S - 2 - 3 + 2 + 3