From 8b45b6f1a021022d732695d39ca377e6f338d37e Mon Sep 17 00:00:00 2001 From: Ruud Date: Wed, 18 Sep 2013 22:07:07 +0200 Subject: [PATCH] Only backup database max once an hour. fix #1218 --- couchpotato/runner.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/couchpotato/runner.py b/couchpotato/runner.py index c57e0770..7403a54f 100644 --- a/couchpotato/runner.py +++ b/couchpotato/runner.py @@ -84,18 +84,6 @@ def runCouchPotato(options, base_path, args, data_dir = None, log_dir = None, En # Backup before start and cleanup old databases new_backup = toUnicode(os.path.join(data_dir, 'db_backup', str(int(time.time())))) - # Create path and copy - if not os.path.isdir(new_backup): os.makedirs(new_backup) - src_files = [options.config_file, db_path, db_path + '-shm', db_path + '-wal'] - for src_file in src_files: - if os.path.isfile(src_file): - dst_file = toUnicode(os.path.join(new_backup, os.path.basename(src_file))) - shutil.copyfile(src_file, dst_file) - - # Try and copy stats seperately - try: shutil.copystat(src_file, dst_file) - except: pass - # Remove older backups, keep backups 3 days or at least 3 backups = [] for directory in os.listdir(os.path.dirname(new_backup)): @@ -103,6 +91,20 @@ def runCouchPotato(options, base_path, args, data_dir = None, log_dir = None, En if os.path.isdir(backup): backups.append(backup) + latest_backup = tryInt(os.path.basename(sorted(backups)[-1])) if len(backups) > 0 else 0 + if latest_backup < time.time() - 3600: + # Create path and copy + if not os.path.isdir(new_backup): os.makedirs(new_backup) + src_files = [options.config_file, db_path, db_path + '-shm', db_path + '-wal'] + for src_file in src_files: + if os.path.isfile(src_file): + dst_file = toUnicode(os.path.join(new_backup, os.path.basename(src_file))) + shutil.copyfile(src_file, dst_file) + + # Try and copy stats seperately + try: shutil.copystat(src_file, dst_file) + except: pass + total_backups = len(backups) for backup in backups: if total_backups > 3: