Compare commits

...

14 Commits

Author SHA1 Message Date
122ef64ad7 build 2025-09-09 11:20:50 +02:00
99f673996e build 2025-09-03 00:44:11 +02:00
68e23da03b build 2025-09-03 00:42:59 +02:00
1c30fb9995 build 2025-09-03 00:42:34 +02:00
b94b61ba5d build 2025-09-03 00:42:04 +02:00
26c3245cf3 build 2025-09-03 00:41:26 +02:00
1510dc2e8d build 2025-09-03 00:40:13 +02:00
d949188a34 build 2025-09-03 00:39:24 +02:00
298c9aee23 build 2025-09-02 22:52:54 +02:00
808f92c4d1 build 2025-09-02 22:50:36 +02:00
43f6d2abcb build 2025-09-02 22:47:01 +02:00
81c7ead7b2 build 2025-09-02 22:44:12 +02:00
cd818da774 build 2025-09-02 22:26:51 +02:00
a1dfbd664c build 2025-09-02 22:23:40 +02:00
2 changed files with 53 additions and 5 deletions

View File

@@ -11,4 +11,5 @@ var_lib_motioneye/*
*/.esphome/build/*
nextcloud/mariadb/*
zabbix-server/postgres-data/*
gitea-runner/*
gitea-runner/*
immich/library/*

View File

@@ -31,7 +31,7 @@ def signal_handler(sig, frame):
signal.signal(signal.SIGINT, signal_handler)
file_path = os.path.realpath(__file__)
dir_path = os.path.dirname(file_path)
VERSION="1.0.9"
VERSION="1.0.10"
# print(file_path)
# print(dir_path)
os.chdir(dir_path)
@@ -110,7 +110,6 @@ for o, a in opts:
elif o in ("-r", "--restore"):
_RESTORE = True
_APP = a
print("RESTORE")
elif o in ("-D", "--dry"):
_EXECUTE = False
elif o in ("-T", "--dry"):
@@ -241,9 +240,12 @@ if _STOP:
cmnd = f"docker stop {c.split()[-1]}"
status, running_containers = subprocess.getstatusoutput(cmnd)
def restore_job(_APP):
#global VERSION
logging.info("Starting Restore")
print(f"Starting restore : {VERSION}")
now = datetime.datetime.now()
STARTTIME = now.strftime("%Y-%m-%d_%H:%M:%S")
_DATE = "pick"
if _APP == "all":
_DATE = "latest"
if host == "rpi5.home.lan" or host == "rpi5":
@@ -256,6 +258,7 @@ def restore_job(_APP):
#input("????")
else:
_APP = _APP.split(",")
PROGRESS = 0
topic = "sectorq/amd/restore"
step = 100 / len(_APP)
@@ -277,7 +280,7 @@ def restore_job(_APP):
if _DATE == "pick":
cmnd = f"ssh root@amd.home.lan 'ls {BACKUP_DEVICE}/backup/m-server/docker_data'"
status, output = subprocess.getstatusoutput(cmnd)
print(output)
# print(output)
dates = output.splitlines()
n = 1
for i in dates:
@@ -600,7 +603,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 +639,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")