Add backup days option

This commit is contained in:
JonnyWong16 2016-10-08 22:29:30 -07:00
parent 010c12da67
commit 1c087ec856
4 changed files with 23 additions and 8 deletions

View file

@ -79,12 +79,12 @@ def make_backup(cleanup=False, scheduler=False):
db.connection.rollback()
if cleanup:
# Delete all scheduled backup files except from the last 5.
now = time.time()
# Delete all scheduled backup older than BACKUP_DAYS.
for root, dirs, files in os.walk(backup_folder):
db_files = [os.path.join(root, f) for f in files if f.endswith('.sched.db')]
if len(db_files) > 5:
backups_sorted_on_age = sorted(db_files, key=os.path.getctime, reverse=True)
for file_ in backups_sorted_on_age[5:]:
for file_ in db_files:
if os.stat(file_).st_mtime < now - plexpy.CONFIG.BACKUP_DAYS * 86400:
try:
os.remove(file_)
except OSError as e: