From 4f868047be5c1bcf3d6932b2fdd7e7b9cf10bde7 Mon Sep 17 00:00:00 2001 From: jaydee Date: Tue, 26 Aug 2025 14:48:39 +0200 Subject: [PATCH] build --- omv_backup.py | 70 +++------------------------------------------------ 1 file changed, 3 insertions(+), 67 deletions(-) diff --git a/omv_backup.py b/omv_backup.py index fc54778..a6d007d 100755 --- a/omv_backup.py +++ b/omv_backup.py @@ -108,8 +108,6 @@ for o, a in opts: _RESTORE = True _APP = a print("RESTORE") - elif o in ("-b", "--backup"): - _BACKUP = True elif o in ("-D", "--dry"): _EXECUTE = False elif o in ("-T", "--dry"): @@ -575,33 +573,6 @@ def backup_job(server): msg = {"mode":_MODE, "status":"started","bak_name":"complete","host":host,"cur_job":b,"sub":line[0],"start_time":STARTTIME,"end_time":"in progress","progress":str(round(progress)) + "%","finished":",".join(finished)} send_mqtt_message(topic,msg) progress = progress + step - # input(apps) - - # for a in apps: - # logging.info(f"App {a}") - # topic = "sectorq/amd/backups" - # msg = {"mode":_MODE, "status":"started","bak_name":"complete","host":host,"cur_job":b,"sub":a,"start_time":STARTTIME,"end_time":"in progress","progress":round(progress),"finished":",".join(finished)} - # send_mqtt_message(topic,msg) - # logger.debug(cmnd) - # if _FIRST: - # cmnd = f"rsync -avz --delete {SOURCE_DIR} --exclude=\"jellyfin/cache/transcodes\" --exclude=\"gitlab/logs/prometheus\" --exclude=\"home-assistant.log\" --exclude=\"gitlab/logs/*\" --exclude=\"esphome/config/.esphome\" --exclude=\".cache\" --exclude=\".git\" --exclude=\"var_lib_motioneye\" rsync://{BACKUP_HOST}{BACKUP_PATH}" - # else: - # cmnd = f"rsync -avz --delete {BACKUP_DIR}{a} --link-dest {FULL_BACKUP_LATEST}/{a} --exclude=\"jellyfin/cache/transcodes\" --exclude=\"gitlab/logs/prometheus\" --exclude=\"home-assistant.log\" --exclude=\"gitlab/logs/*\" --exclude=\"esphome/config/.esphome\" --exclude=\".cache\" --exclude=\".git\" --exclude=\"var_lib_motioneye\" {NEW_BACKUP_DIR}" - - # ans = "y" - # logging.info(cmnd) - # logging.info("Sync files1") - # #input("??????") - # if _TEST: - # ans = input("continue?") or "n" - # if ans == "y" and _EXECUTE: - # status, output = subprocess.getstatusoutput(cmnd) - # #proc = subprocess.Popen(cmnd,stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE,cwd = "/myapps/",shell=True) - # progress = progress + step - # topic = "sectorq/amd/backups" - # msg = {"mode":_MODE, "status":"started","bak_name":"complete","host":host,"cur_job":b,"sub":a,"start_time":STARTTIME,"end_time":"in progress","progress":round(progress),"finished":",".join(finished)} - # send_mqtt_message(topic,msg) - cmnd = f"rm -rf {FULL_BACKUP_LATEST}" @@ -620,18 +591,11 @@ def backup_job(server): if _EXECUTE: status, output = subprocess.getstatusoutput(cmnd) - #Remove old logging.info("Removing old dirs") - # input("????") - #cmnd = "find {} -maxdepth 1 -type d -mtime +30 -exec rm -rf {{}} \;".format(BACKUP_DIR) - #cmnd = f"cd {BACKUP_ROOT} find ./ -maxdepth 1 -type d -mmin +30 -exec rm -rf {{}} \\;" cmnd = f"ls {BACKUP_ROOT}" - - - #print(cmnd) - # input("????") + if _EXECUTE: status, output = subprocess.getstatusoutput(cmnd) for f in output.splitlines(): @@ -688,6 +652,7 @@ def backup_job(server): topic = "sectorq/amd/restore" for s in servers: + logging.info(f"Restoring {s}") #if s != "rack.home.lan": if s == "m-server.home.lan": continue @@ -728,39 +693,10 @@ def backup_job(server): os.remove("/backups/restore") except: pass - # if _MODE == "auto": - # hostup = True - # cmnd = "ssh root@omv.home.lan 'systemctl suspend &'" - # status, output = subprocess.getstatusoutput(cmnd) - # while hostup: - # #HOST_UP = os.system(f"ping -c 1 -w 2 omv.home.lan") == 0 - # cmnd = f"ping -c 1 -w 2 {BACKUP_HOST}" - # status, output = subprocess.getstatusoutput(cmnd) - # # print(status) - # # print(output) - - - # if status == 0: - # print(f"Backup host up, waiting - {n}\r", end="") - # time.sleep(5) - # n += 1 - # else: - # print("Backup host down " ) - # hostup = False - - - - # try: - # url = "http://m-server.home.lan:8123/api/webhook/-0eWYFhSTzdusAO8jwQS9t1AT?mode=off" - # x = requests.post(url) - - # print(x.text) - # except: - # pass message= "finished1" client.publish(topic, message,qos=2,retain=True) - return 0 + if _RESTORE: restore_job() sys.exit()