Skip to content

Commit

Permalink
Fix pruning of backups
Browse files Browse the repository at this point in the history
  • Loading branch information
aknuds1 committed Jan 11, 2016
1 parent d7e1a4c commit 53ee82d
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions backup_rethinkdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,17 @@ def backup_rethinkdb(rethinkdb_host, s3_bucket, remove_local_backup):
retention_period = 100
resp = s3_client.list_objects(Bucket=s3_bucket)
now = datetime.now(timezone.utc)
_logger.info('Pruning backups on S3 older than {} days...'.format(
retention_period))
for obj in [o for o in resp['Contents'] if o['Key'].startswith(
'rethinkdb-dump')]:
key = obj['Key']
last_modified = obj['LastModified']
gap = now - last_modified
if gap.days > retention_period or True:
_logger.info('Deleting \'{}\'...'.format(key))
if gap.days > retention_period:
_logger.info(
'Pruning backup on S3 \'{}\' since its date is {}...'
.format(key, last_modified))
s3_client.delete_object(Bucket=s3_bucket, Key=key)

if remove_local_backup:
Expand Down

0 comments on commit 53ee82d

Please sign in to comment.