mirror of
https://gitlab.sectorq.eu/jaydee/omv_backup.git
synced 2025-09-13 04:10:10 +02:00
Compare commits
6 Commits
571219881d
...
298c9aee23
Author | SHA1 | Date | |
---|---|---|---|
298c9aee23 | |||
808f92c4d1 | |||
43f6d2abcb | |||
81c7ead7b2 | |||
cd818da774 | |||
a1dfbd664c |
@@ -600,7 +600,7 @@ def backup_job(pl):
|
||||
#logging.info(cmnd)
|
||||
logging.info("Removing latest link")
|
||||
# input("????")
|
||||
if _EXECUTE:
|
||||
if not _DRYRUN:
|
||||
status, output = subprocess.getstatusoutput(cmnd)
|
||||
if _FIRST:
|
||||
cmnd = f"cd {BACKUP_ROOT}; ln -s initial latest"
|
||||
@@ -636,6 +636,50 @@ def backup_job(pl):
|
||||
shutil.rmtree(dir_path)
|
||||
else:
|
||||
print("No match.")
|
||||
if not _DRYRUN:
|
||||
logging.info(f"Clearing multiple days")
|
||||
multiple_per_day = {}
|
||||
to_remove = []
|
||||
for f in output.splitlines():
|
||||
pattern = r"^[0-9]{4}-[0-9]{2}-[0-9]{2}_[0-9]{2}-[0-9]{2}-[0-9]{2}$" # regex pattern: string starts with 'abc'
|
||||
|
||||
if re.match(pattern, f):
|
||||
cday = f.split("_")[0]
|
||||
if cday in multiple_per_day:
|
||||
multiple_per_day[cday].append(f)
|
||||
else:
|
||||
multiple_per_day[cday] = [f]
|
||||
|
||||
|
||||
|
||||
|
||||
# # logging.info("Match!")
|
||||
# dt = datetime.datetime.strptime(f, "%Y-%m-%d_%H-%M-%S")
|
||||
# epoch_time = int(dt.timestamp())
|
||||
# now_epoch = int(datetime.datetime.now().timestamp())
|
||||
|
||||
|
||||
# x = now_epoch - epoch_time
|
||||
# # logging.info(epoch_time) # Output: 45
|
||||
# if x > 2592000:
|
||||
# dir_path = f"{BACKUP_ROOT}/{f}"
|
||||
# logging.info(f"removing {dir_path}")
|
||||
# shutil.rmtree(dir_path)
|
||||
else:
|
||||
print("No match.")
|
||||
logging.info(f"Clearing multiple days: {multiple_per_day}")
|
||||
for f in multiple_per_day:
|
||||
logging.info(f"Looping multiple_per_day : {f}")
|
||||
if len(multiple_per_day[f]) > 1:
|
||||
last = multiple_per_day[f][-1]
|
||||
multiple_per_day[f].pop()
|
||||
logging.info(f"Last from day: {last}")
|
||||
for d in multiple_per_day[f]:
|
||||
logging.info(f"Looping multiple_per_day : {f} : {d}")
|
||||
dir_path = f"{BACKUP_ROOT}/{d}"
|
||||
logging.info(f"removing {dir_path}")
|
||||
shutil.rmtree(dir_path)
|
||||
|
||||
|
||||
cmnd = f"ls {BACKUP_ROOT}|grep _running"
|
||||
logging.info(f"removing obsolete dirs")
|
||||
|
Reference in New Issue
Block a user