Permalink
Browse files

Added granular retention periods

Added granular retention periods using primitives. See README.md for details
Closes #11
  • Loading branch information...
1 parent f128f6d commit d834dc0b449d24926f1343f4863430e55b7a2f8d Kevin Landreth committed Dec 13, 2012
Showing with 48 additions and 4 deletions.
  1. +13 −0 README.md
  2. +35 −4 slbackup.py
View
@@ -27,6 +27,19 @@ file comparisions are being performed.
comparisions using this hash instead of time/size variance.
* Open source - MIT licensed (as is the object storage library).
+
+Retention formats
+-----------------
+
+When specifying retention in the config file or _-r_ in the cli args, please be
+advised of the new time formats below:
+
+* time in days (1, 30, 15, etc)
+* time specific unit (1s, 50d, 5w, 2h, 40m)
+ * supported units: *s*econds, *m*inutes, *d*ays, *h*ours, *w*eeks
+ * *cannot* stack time units (1d10m) - calculate it if you need this
+
+
Usage
=====
View
@@ -135,7 +135,7 @@ def __init__(self, options):
self.dc = c.get('slbackup', 'datacenter')
self.use_private = c.getboolean('slbackup', 'internal')
self.checkhash = c.getboolean('slbackup', 'checksum')
- self.retention = c.getint('slbackup', 'retention')
+ self.retention = c.get('slbackup', 'retention')
self.threads = c.getint('slbackup', 'threads')
self.excludes = []
self.source = options.get('source')
@@ -195,6 +195,38 @@ def __init__(self, options):
sys.exit(0)
+ @property
+ def retention(self):
+ return self._retention
+
+ @retention.setter
+ def retention(self, value):
+ intval = None
+ unit = None
+
+ # see if they passed in just a numeric string
+ # if so, set it to the number of days
+ try:
+ intval = int(value)
+ unit = 'd'
+ except ValueError:
+ unit = value[-1]
+ intval = int(value[:-1])
+
+ units = {
+ 's': 1,
+ 'm': 60,
+ 'h': 60 * 60,
+ 'd': 24 * 60 * 60,
+ 'w': 7 * 24 * 60 * 60,
+ }
+
+ if unit not in units:
+ raise ValueError("Invalid time value '%s'. Must be one of %s"
+ % (unit, ', '.join(units.keys()),))
+
+ self._retention = units[unit] * int(intval)
+
def try_datetime_parse(self, datetime_str):
"""
Tries to parse the datetime and return the UNIX epoc version of time
@@ -277,8 +309,7 @@ def delete_later(self, obj):
Deletes a file after the specified number of days
"""
l = logging.getLogger("delete_later")
- delta = int(self.retention) * 24 * 60 * 60
- when = int(time.time()) + delta
+ when = int(time.time()) + self.retention
l.debug("Setting retention(%d) on %s", when, obj.name)
headers = {
@@ -689,7 +720,7 @@ def upload_directory(app):
" configuration file."
"Specifying them via the command line will override the config file")
- oargs.add_option('-r', '--retention', nargs=1, type="int",
+ oargs.add_option('-r', '--retention', nargs=1, type="str",
help='Days of retention to keep updated and deleted files.'
' This will create a backupContainer-revisions container.'
' Set to 0 to delete and overwrite files immediately.'

0 comments on commit d834dc0

Please sign in to comment.