mirror of
				https://gitlab.sectorq.eu/jaydee/omv_backup.git
				synced 2025-10-30 10:01:11 +01:00 
			
		
		
		
	build
This commit is contained in:
		| @@ -198,7 +198,7 @@ logging.info("Test connection") | |||||||
| hm = socket.gethostbyaddr(BACKUP_HOST) | hm = socket.gethostbyaddr(BACKUP_HOST) | ||||||
|  |  | ||||||
| logging.info(_RESTORE) | logging.info(_RESTORE) | ||||||
| def send_mqtt_message(msg): | def send_mqtt_message(topic,msg): | ||||||
|     try: |     try: | ||||||
|         client.connect(broker,1883,60) |         client.connect(broker,1883,60) | ||||||
|         client.publish(topic, json.dumps(msg)) |         client.publish(topic, json.dumps(msg)) | ||||||
| @@ -259,7 +259,7 @@ def restore_job(): | |||||||
|         logging.info(msg) |         logging.info(msg) | ||||||
|          |          | ||||||
|          |          | ||||||
|         send_mqtt_message(msg) |         send_mqtt_message(topic,msg) | ||||||
|         PROGRESS = PROGRESS + step |         PROGRESS = PROGRESS + step | ||||||
|         now = datetime.datetime.now() |         now = datetime.datetime.now() | ||||||
|         DATETIME = now.strftime("%Y-%m-%d_%H-%M-%S") |         DATETIME = now.strftime("%Y-%m-%d_%H-%M-%S") | ||||||
| @@ -468,7 +468,7 @@ def restore_job(): | |||||||
|     msg = {"mode":_MODE, "status":"restore","bak_name":"Restore","host":host,"cur_job":app,"start_time":STARTTIME,"end_time":"","progress":100,"finished":ENDJOB,"used_space":1} |     msg = {"mode":_MODE, "status":"restore","bak_name":"Restore","host":host,"cur_job":app,"start_time":STARTTIME,"end_time":"","progress":100,"finished":ENDJOB,"used_space":1} | ||||||
|     logging.info(msg) |     logging.info(msg) | ||||||
|      |      | ||||||
|     send_mqtt_message(msg) |     send_mqtt_message(topic,msg) | ||||||
|     if _MODE == "auto": |     if _MODE == "auto": | ||||||
|         cmnd = "ssh root@amd.home.lan 'systemctl suspend &'" |         cmnd = "ssh root@amd.home.lan 'systemctl suspend &'" | ||||||
|         status, output = subprocess.getstatusoutput(cmnd) |         status, output = subprocess.getstatusoutput(cmnd) | ||||||
| @@ -482,10 +482,10 @@ def backup_job(server): | |||||||
|     STARTTIME = now.strftime("%Y-%m-%d_%H:%M:%S") |     STARTTIME = now.strftime("%Y-%m-%d_%H:%M:%S") | ||||||
|     topic = "sectorq/amd/restore" |     topic = "sectorq/amd/restore" | ||||||
|     msg = {"mode":"restore", "status":"restore","bak_name":"s","host":0,"cur_job":"aaa","start_time":1,"end_time":1,"progress":0,"finished":0,"used_space":0} |     msg = {"mode":"restore", "status":"restore","bak_name":"s","host":0,"cur_job":"aaa","start_time":1,"end_time":1,"progress":0,"finished":0,"used_space":0} | ||||||
|     send_mqtt_message(msg) |     send_mqtt_message(topic,msg) | ||||||
|     topic = "sectorq/amd/backups" |     topic = "sectorq/amd/backups" | ||||||
|     msg = {"mode":_MODE, "status":"started","bak_name":"complete","host":"","cur_job":"","start_time":STARTTIME,"end_time":"in progress","progress":0,"finished":",".join(finished)} |     msg = {"mode":_MODE, "status":"started","bak_name":"complete","host":"","cur_job":"","start_time":STARTTIME,"end_time":"in progress","progress":0,"finished":",".join(finished)} | ||||||
|     send_mqtt_message(msg) |     send_mqtt_message(topic,msg) | ||||||
|      |      | ||||||
|     # iterate over files in  |     # iterate over files in  | ||||||
|     # that directory |     # that directory | ||||||
| @@ -498,7 +498,7 @@ def backup_job(server): | |||||||
|         if not backups[host]["jobs"][b]["active"]: |         if not backups[host]["jobs"][b]["active"]: | ||||||
|             logging.info("Backup {} is not active!".format(b)) |             logging.info("Backup {} is not active!".format(b)) | ||||||
|             msg = {"status":"inactive","bak_name":b,"start_time":"inactive","end_time":"inactive","progress":0} |             msg = {"status":"inactive","bak_name":b,"start_time":"inactive","end_time":"inactive","progress":0} | ||||||
|             send_mqtt_message(msg) |             send_mqtt_message(topic,msg) | ||||||
|             continue |             continue | ||||||
|  |  | ||||||
|         SOURCE_DIR = backups[host]["jobs"][b]["source"] |         SOURCE_DIR = backups[host]["jobs"][b]["source"] | ||||||
| @@ -567,7 +567,7 @@ def backup_job(server): | |||||||
|                 #print(len(apps)) |                 #print(len(apps)) | ||||||
|                 topic = "sectorq/amd/backups" |                 topic = "sectorq/amd/backups" | ||||||
|                 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)} |                 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(msg) |                 send_mqtt_message(topic,msg) | ||||||
|                 progress = progress + step |                 progress = progress + step | ||||||
|         # input(apps) |         # input(apps) | ||||||
|  |  | ||||||
| @@ -575,7 +575,7 @@ def backup_job(server): | |||||||
|         #     logging.info(f"App {a}") |         #     logging.info(f"App {a}") | ||||||
|         #     topic = "sectorq/amd/backups" |         #     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)} |         #     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(msg)  |         #     send_mqtt_message(topic,msg)  | ||||||
|         #     logger.debug(cmnd) |         #     logger.debug(cmnd) | ||||||
|         #     if _FIRST: |         #     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}"      |         #         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}"      | ||||||
| @@ -594,7 +594,7 @@ def backup_job(server): | |||||||
|         #     progress = progress + step |         #     progress = progress + step | ||||||
|         #     topic = "sectorq/amd/backups" |         #     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)} |         #     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(msg)  |         #     send_mqtt_message(topic,msg)  | ||||||
|                  |                  | ||||||
|              |              | ||||||
|         cmnd = f"rm -rf {FULL_BACKUP_LATEST}" |         cmnd = f"rm -rf {FULL_BACKUP_LATEST}" | ||||||
| @@ -635,6 +635,7 @@ def backup_job(server): | |||||||
|                     logging.info("Match!") |                     logging.info("Match!") | ||||||
|                     dt = datetime.datetime.strptime(f, "%Y-%m-%d_%H-%M-%S") |                     dt = datetime.datetime.strptime(f, "%Y-%m-%d_%H-%M-%S") | ||||||
|                     epoch_time = int(dt.timestamp()) |                     epoch_time = int(dt.timestamp()) | ||||||
|  |                      | ||||||
|                     now_epoch = int(datetime.datetime.now().timestamp()) |                     now_epoch = int(datetime.datetime.now().timestamp()) | ||||||
|                     x = now_epoch - epoch_time |                     x = now_epoch - epoch_time | ||||||
|                     # logging.info(epoch_time)  # Output: 45 |                     # logging.info(epoch_time)  # Output: 45 | ||||||
| @@ -661,7 +662,7 @@ def backup_job(server): | |||||||
|         #msg = {"status":"finished","bak_name":b,"start_time":DATETIME,"end_time":ENDTIME,"progress":0} |         #msg = {"status":"finished","bak_name":b,"start_time":DATETIME,"end_time":ENDTIME,"progress":0} | ||||||
|         finished.append(b) |         finished.append(b) | ||||||
|         msg = {"mode":_MODE, "status":"finished","bak_name":"complete","host":host,"cur_job":b,"start_time":ENDTIME,"end_time":"in progress","progress":0,"finished":",".join(finished)} |         msg = {"mode":_MODE, "status":"finished","bak_name":"complete","host":host,"cur_job":b,"start_time":ENDTIME,"end_time":"in progress","progress":0,"finished":",".join(finished)} | ||||||
|         send_mqtt_message(msg) |         send_mqtt_message(topic,msg) | ||||||
|  |  | ||||||
|     logging.info("Getting size of FS") |     logging.info("Getting size of FS") | ||||||
|     cmnd = "df -h /mnt/raid|awk '{ print $3 }'|tail -1" |     cmnd = "df -h /mnt/raid|awk '{ print $3 }'|tail -1" | ||||||
| @@ -676,7 +677,7 @@ def backup_job(server): | |||||||
|     msg = {"mode":_MODE, "status":"finished","bak_name":"complete","host":host,"cur_job":b,"start_time":STARTTIME,"end_time":ENDTIME,"progress":0,"finished":",".join(finished),"used_space":used_space} |     msg = {"mode":_MODE, "status":"finished","bak_name":"complete","host":host,"cur_job":b,"start_time":STARTTIME,"end_time":ENDTIME,"progress":0,"finished":",".join(finished),"used_space":used_space} | ||||||
|     logging.info(msg) |     logging.info(msg) | ||||||
|      |      | ||||||
|     send_mqtt_message(msg) |     send_mqtt_message(topic,msg) | ||||||
|  |  | ||||||
|      |      | ||||||
|     topic = "sectorq/amd/restore" |     topic = "sectorq/amd/restore" | ||||||
| @@ -693,7 +694,7 @@ def backup_job(server): | |||||||
|         msg = {"mode":_MODE, "status":"restore","bak_name":"s","host":s,"cur_job":"aaa","start_time":1,"end_time":1,"progress":0,"finished":1,"used_space":1} |         msg = {"mode":_MODE, "status":"restore","bak_name":"s","host":s,"cur_job":"aaa","start_time":1,"end_time":1,"progress":0,"finished":1,"used_space":1} | ||||||
|         logging.info(msg) |         logging.info(msg) | ||||||
|          |          | ||||||
|         send_mqtt_message(msg) |         send_mqtt_message(topic,msg) | ||||||
|         if is_port_open(s,22): |         if is_port_open(s,22): | ||||||
|             ssh = paramiko.SSHClient() |             ssh = paramiko.SSHClient() | ||||||
|             ssh.load_system_host_keys() |             ssh.load_system_host_keys() | ||||||
| @@ -768,7 +769,7 @@ if _SSH_TEST: | |||||||
|         msg = {"mode":_MODE, "status":"restore","bak_name":"s","host":s,"cur_job":"aaa","start_time":1,"end_time":1,"progress":0,"finished":1,"used_space":1} |         msg = {"mode":_MODE, "status":"restore","bak_name":"s","host":s,"cur_job":"aaa","start_time":1,"end_time":1,"progress":0,"finished":1,"used_space":1} | ||||||
|         logging.info(msg) |         logging.info(msg) | ||||||
|          |          | ||||||
|         send_mqtt_message(msg) |         send_mqtt_message(topic,msg) | ||||||
|         if s != "rack.home.lan": |         if s != "rack.home.lan": | ||||||
|             continue |             continue | ||||||
|         if is_port_open(s,22): |         if is_port_open(s,22): | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user