mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-16 02:02:58 -07:00
Add backup days option
This commit is contained in:
parent
010c12da67
commit
1c087ec856
4 changed files with 23 additions and 8 deletions
|
@ -153,6 +153,19 @@
|
|||
</div>
|
||||
<p class="help-block">The interval (in hours) PlexPy will backup the database and configuration file. Minimum 1, maximum 24, default 6.</p>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="backup_interval">Backup Days</label>
|
||||
<div class="row">
|
||||
<div class="col-md-2">
|
||||
<input type="text" class="form-control" data-parsley-type="integer" id="backup_days" name="backup_days" value="${config['backup_days']}" size="5" data-parsley-min="1" data-parsley-trigger="change" data-parsley-errors-container="#backup_days_error" required>
|
||||
</div>
|
||||
<div id="backup_days_error" class="alert alert-danger settings-alert" role="alert"></div>
|
||||
</div>
|
||||
<p class="help-block">
|
||||
The number of days to keep scheduled backups. Minimum 1, default 3.<br />
|
||||
Note: Manual backups are not removed automatically.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="padded-header">
|
||||
<h3>Directories</h3>
|
||||
|
|
|
@ -101,6 +101,7 @@ _CONFIG_DEFINITIONS = {
|
|||
'BROWSER_ON_NEWDEVICE': (int, 'Browser', 0),
|
||||
'BUFFER_THRESHOLD': (int, 'Monitoring', 3),
|
||||
'BUFFER_WAIT': (int, 'Monitoring', 900),
|
||||
'BACKUP_DAYS': (int, 'General', 3),
|
||||
'BACKUP_DIR': (str, 'General', ''),
|
||||
'BACKUP_INTERVAL': (int, 'General', 6),
|
||||
'CACHE_DIR': (str, 'General', ''),
|
||||
|
@ -604,12 +605,12 @@ def make_backup(cleanup=False, scheduler=False):
|
|||
shutil.copyfile(plexpy.CONFIG_FILE, backup_file_fp)
|
||||
|
||||
if cleanup:
|
||||
now = time.time()
|
||||
# Delete all scheduled backup files except from the last 5.
|
||||
for root, dirs, files in os.walk(backup_folder):
|
||||
db_files = [os.path.join(root, f) for f in files if f.endswith('.sched.ini')]
|
||||
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:]:
|
||||
ini_files = [os.path.join(root, f) for f in files if f.endswith('.sched.ini')]
|
||||
for file_ in ini_files:
|
||||
if os.stat(file_).st_mtime < now - plexpy.CONFIG.BACKUP_DAYS * 86400:
|
||||
try:
|
||||
os.remove(file_)
|
||||
except OSError as e:
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -2527,6 +2527,7 @@ class WebInterface(object):
|
|||
"api_key": plexpy.CONFIG.API_KEY,
|
||||
"update_db_interval": plexpy.CONFIG.UPDATE_DB_INTERVAL,
|
||||
"freeze_db": checked(plexpy.CONFIG.FREEZE_DB),
|
||||
"backup_days": plexpy.CONFIG.BACKUP_DAYS,
|
||||
"backup_dir": plexpy.CONFIG.BACKUP_DIR,
|
||||
"backup_interval": plexpy.CONFIG.BACKUP_INTERVAL,
|
||||
"cache_dir": plexpy.CONFIG.CACHE_DIR,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue