This commit is contained in:
2025-09-02 22:23:40 +02:00
parent 571219881d
commit a1dfbd664c

View File

@@ -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,42 @@ def backup_job(pl):
shutil.rmtree(dir_path)
else:
print("No match.")
if not _DRYRUN:
logging.info(f"Clearing multiple days")
multiple_per_day = {}
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}")
cmnd = f"ls {BACKUP_ROOT}|grep _running"
logging.info(f"removing obsolete dirs")