- datetime_len = 19
- now = str(datetime.datetime.now())[:datetime_len]
- while datetime_len > 2:
- # assume backup_dates starts with oldest dates
- for i, date in enumerate(backup_dates):
- if date[:datetime_len] == now:
- if i not in to_save:
- to_save += [i]
- break
- datetime_len -= 1
- now = now[:datetime_len]
+ for age in ages_to_keep:
+ limit = now - age
+ for i, date in enumerate(reversed(backup_dates)):
+ if datetime.strptime(date, '%Y-%m-%d %H:%M:%S.%f') < limit:
+ unreversed_i = len(backup_dates) - i - 1
+ if unreversed_i not in to_save:
+ to_save += [unreversed_i]
+ break