mirror of
https://gitlab.sectorq.eu/jaydee/omv_backup.git
synced 2025-09-13 12:10:12 +02:00
build
This commit is contained in:
@@ -198,7 +198,7 @@ logging.info("Test connection")
|
||||
hm = socket.gethostbyaddr(BACKUP_HOST)
|
||||
|
||||
logging.info(_RESTORE)
|
||||
def send_mqtt_message(msg):
|
||||
def send_mqtt_message(topic,msg):
|
||||
try:
|
||||
client.connect(broker,1883,60)
|
||||
client.publish(topic, json.dumps(msg))
|
||||
@@ -259,7 +259,7 @@ def restore_job():
|
||||
logging.info(msg)
|
||||
|
||||
|
||||
send_mqtt_message(msg)
|
||||
send_mqtt_message(topic,msg)
|
||||
PROGRESS = PROGRESS + step
|
||||
now = datetime.datetime.now()
|
||||
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}
|
||||
logging.info(msg)
|
||||
|
||||
send_mqtt_message(msg)
|
||||
send_mqtt_message(topic,msg)
|
||||
if _MODE == "auto":
|
||||
cmnd = "ssh root@amd.home.lan 'systemctl suspend &'"
|
||||
status, output = subprocess.getstatusoutput(cmnd)
|
||||
@@ -482,10 +482,10 @@ 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(msg)
|
||||
send_mqtt_message(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(msg)
|
||||
send_mqtt_message(topic,msg)
|
||||
|
||||
# iterate over files in
|
||||
# that directory
|
||||
@@ -498,7 +498,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(msg)
|
||||
send_mqtt_message(topic,msg)
|
||||
continue
|
||||
|
||||
SOURCE_DIR = backups[host]["jobs"][b]["source"]
|
||||
@@ -567,7 +567,7 @@ def backup_job(server):
|
||||
#print(len(apps))
|
||||
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)}
|
||||
send_mqtt_message(msg)
|
||||
send_mqtt_message(topic,msg)
|
||||
progress = progress + step
|
||||
# input(apps)
|
||||
|
||||
@@ -575,7 +575,7 @@ def backup_job(server):
|
||||
# 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(msg)
|
||||
# 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}"
|
||||
@@ -594,7 +594,7 @@ def backup_job(server):
|
||||
# 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(msg)
|
||||
# send_mqtt_message(topic,msg)
|
||||
|
||||
|
||||
cmnd = f"rm -rf {FULL_BACKUP_LATEST}"
|
||||
@@ -635,6 +635,7 @@ def backup_job(server):
|
||||
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
|
||||
@@ -661,7 +662,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(msg)
|
||||
send_mqtt_message(topic,msg)
|
||||
|
||||
logging.info("Getting size of FS")
|
||||
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}
|
||||
logging.info(msg)
|
||||
|
||||
send_mqtt_message(msg)
|
||||
send_mqtt_message(topic,msg)
|
||||
|
||||
|
||||
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}
|
||||
logging.info(msg)
|
||||
|
||||
send_mqtt_message(msg)
|
||||
send_mqtt_message(topic,msg)
|
||||
if is_port_open(s,22):
|
||||
ssh = paramiko.SSHClient()
|
||||
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}
|
||||
logging.info(msg)
|
||||
|
||||
send_mqtt_message(msg)
|
||||
send_mqtt_message(topic,msg)
|
||||
if s != "rack.home.lan":
|
||||
continue
|
||||
if is_port_open(s,22):
|
||||
|
Reference in New Issue
Block a user