Remove older backup folders
This commit is contained in:
1 parent
11e7fb23ca
commit
6fa6d530ec
1 file changed
+13
-7
+13
-7
@@ -9,6 +9,7 @@ import traceback
|
|||||||
import warnings
|
import warnings
|
||||||
import re
|
import re
|
||||||
import tarfile
|
import tarfile
|
||||||
|
import shutil
|
||||||
|
|
||||||
from CodernityDB.database_super_thread_safe import SuperThreadSafeDatabase
|
from CodernityDB.database_super_thread_safe import SuperThreadSafeDatabase
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
@@ -108,14 +109,19 @@ def runCouchPotato(options, base_path, args, data_dir = None, log_dir = None, En
|
|||||||
if not os.path.isdir(backup_path): os.makedirs(backup_path)
|
if not os.path.isdir(backup_path): os.makedirs(backup_path)
|
||||||
|
|
||||||
for root, dirs, files in os.walk(backup_path):
|
for root, dirs, files in os.walk(backup_path):
|
||||||
for backup_file in sorted(files):
|
# Only consider files being a direct child of the backup_path
|
||||||
ints = re.findall('\d+', backup_file)
|
if root == backup_path:
|
||||||
|
for backup_file in sorted(files):
|
||||||
|
ints = re.findall('\d+', backup_file)
|
||||||
|
|
||||||
# Delete non zip files
|
# Delete non zip files
|
||||||
if len(ints) != 1:
|
if len(ints) != 1:
|
||||||
os.remove(os.path.join(backup_path, backup_file))
|
os.remove(os.path.join(root, backup_file))
|
||||||
else:
|
else:
|
||||||
existing_backups.append((int(ints[0]), backup_file))
|
existing_backups.append((int(ints[0]), backup_file))
|
||||||
|
else:
|
||||||
|
# Delete stray directories.
|
||||||
|
shutil.rmtree(root)
|
||||||
|
|
||||||
# Remove all but the last 5
|
# Remove all but the last 5
|
||||||
for eb in existing_backups[:-backup_count]:
|
for eb in existing_backups[:-backup_count]:
|
||||||
|
|||||||
Reference in new issue
Block a user