This commit is contained in:
2025-08-26 15:51:51 +02:00
parent 1816bd516c
commit f9e7654c47

View File

@@ -479,6 +479,9 @@ def restore_job():
status, output = subprocess.getstatusoutput(cmnd)
def backup_job(server):
client = mqtt.Client()
client.username_pw_set("jaydee", "jaydee1")
client.connect("mqtt.home.lan",1883,60)
logging.info(f'starting backup job')
finished = []
@@ -486,11 +489,12 @@ def backup_job(server):
STARTTIME = now.strftime("%Y-%m-%d_%H:%M:%S")
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}
send_mqtt_message(topic,msg)
client.publish(topic, json.dumps(msg),qos=0, retain=True)
#client.publish(topic, msg)
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)}
send_mqtt_message(topic,msg)
client.publish(topic, json.dumps(msg),qos=0, retain=True)
# iterate over files in
# that directory
@@ -503,7 +507,7 @@ def backup_job(server):
if not backups[host]["jobs"][b]["active"]:
logging.info("Backup {} is not active!".format(b))
msg = {"status":"inactive","bak_name":b,"start_time":"inactive","end_time":"inactive","progress":0}
send_mqtt_message(topic,msg)
client.publish(topic, json.dumps(msg),qos=0, retain=True)
continue
SOURCE_DIR = backups[host]["jobs"][b]["source"]
@@ -523,9 +527,9 @@ def backup_job(server):
# msg = {"status":"started","bak_name":b,"start_time":DATETIME,"end_time":"in progress", "progress":0}
msg = {"mode":_MODE, "status":"started","bak_name":"complete","host":host,"cur_job":b,"start_time":STARTTIME,"end_time":"in progress","progress":0,"finished":",".join(finished)}
client.connect(broker,1883,60)
client.publish(topic, json.dumps(msg),qos=0, retain=True)
client.disconnect()
cmnd = "mkdir -p " + NEW_BACKUP_DIR
@@ -626,7 +630,7 @@ def backup_job(server):
#msg = {"status":"finished","bak_name":b,"start_time":DATETIME,"end_time":ENDTIME,"progress":0}
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)}
send_mqtt_message(topic,msg)
client.publish(topic, json.dumps(msg),qos=0, retain=True)
logging.info("Getting size of FS")
cmnd = "df -h /mnt/raid|awk '{ print $3 }'|tail -1"
@@ -641,10 +645,11 @@ 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}
logging.info(msg)
send_mqtt_message(topic,msg)
client.publish(topic, json.dumps(msg),qos=0, retain=True)
topic = "sectorq/backups/start"
logging.info(f"LALA : {topic}")
send_mqtt_message(topic, "finished",qos=2,retain=True)
client.publish(topic, "finished",qos=0, retain=True)
client.disconnect()
return "finished"