mirror of
https://gitlab.sectorq.eu/jaydee/omv_backup.git
synced 2025-07-01 23:58:33 +02:00
added v3
This commit is contained in:
@ -93,7 +93,6 @@ try:
|
||||
except:
|
||||
client = mqtt_client.Client()
|
||||
client.username_pw_set(mqtt_username, mqtt_password)
|
||||
client.connect(broker,1883,60)
|
||||
|
||||
|
||||
backups = {
|
||||
@ -150,8 +149,13 @@ hm = socket.gethostbyaddr(BACKUP_HOST)
|
||||
|
||||
print("Starting")
|
||||
print(_RESTORE)
|
||||
|
||||
|
||||
def send_mqtt_message(msg):
|
||||
try:
|
||||
client.connect(broker,1883,60)
|
||||
client.publish(topic, json.dumps(msg))
|
||||
client.disconnect()
|
||||
except:
|
||||
print("Failed to send")
|
||||
|
||||
if _SYNC:
|
||||
containers = ["HomeAssistant","webhub-web-1","heimdall","pihole","mosquitto-mosquitto-1","mailu3-redis-1","mailu3-webmail-1","mailu3-resolver-1","mailu3-antispam-1","mailu3-webdav-1","mailu3-smtp-1","mailu3-oletools-1","mailu3-front-1","mailu3-fetchmail-1","mailu3-imap-1","matter-server","piper-en","openwakeword","whisper-en","auth-worker-1","auth-server-1","auth-authentik_ldap-1","auth-redis-1","auth-postgresql-1","nginx-app-1"]
|
||||
@ -193,13 +197,12 @@ if _RESTORE:
|
||||
_APP = _APP.split(",")
|
||||
|
||||
|
||||
|
||||
|
||||
for app in _APP:
|
||||
topic = "sectorq/amd/restore/{}".format(app)
|
||||
client.connect(broker,1883,60)
|
||||
msg = {"status":"inactive","bak_name":app,"start_time":"inactive","end_time":"inactive","progress":0}
|
||||
|
||||
client.publish(topic, json.dumps(msg))
|
||||
client.disconnect()
|
||||
send_mqtt_message(msg)
|
||||
now = datetime.datetime.now()
|
||||
DATETIME = now.strftime("%Y-%m-%d_%H-%M-%S")
|
||||
BACKUP_HOST = f"root@amd.home.lan"
|
||||
@ -238,10 +241,7 @@ if _RESTORE:
|
||||
|
||||
|
||||
msg = {"status":"started","bak_name":app,"start_time":DATETIME,"end_time":"in progress", "progress":0}
|
||||
client.connect(broker,1883,60)
|
||||
client.publish(topic, json.dumps(msg),2,True)
|
||||
client.disconnect()
|
||||
|
||||
send_mqtt_message(msg)
|
||||
print("Create backup dir")
|
||||
print(cmnd)
|
||||
|
||||
@ -273,6 +273,10 @@ if _RESTORE:
|
||||
status, output = subprocess.getstatusoutput(cmnd)
|
||||
# cmnd = "docker start heimdall"
|
||||
# status, output = subprocess.getstatusoutput(cmnd)
|
||||
|
||||
|
||||
|
||||
|
||||
if app == "ha":
|
||||
print("Stopping docker")
|
||||
cmnd = "docker stop heimdall"
|
||||
@ -288,7 +292,7 @@ if _RESTORE:
|
||||
print("Start docker")
|
||||
# cmnd = "docker start heimdall"
|
||||
# status, output = subprocess.getstatusoutput(cmnd)
|
||||
if app == "fail2ban":
|
||||
elif app == "fail2ban":
|
||||
print("Stopping docker")
|
||||
cmnd = f"rsync -avz --delete {BACKUP_HOST}:{BACKUP_DEVICE}{NEW_BACKUP_DIR} {SOURCE_DIR}"
|
||||
ans = "y"
|
||||
@ -301,7 +305,7 @@ if _RESTORE:
|
||||
print("Start docker")
|
||||
# cmnd = "docker start heimdall"
|
||||
# status, output = subprocess.getstatusoutput(cmnd)
|
||||
elif app == "nginx":
|
||||
elif app == "nginx1":
|
||||
print("Stopping docker")
|
||||
cmnd = "docker stop nginx-app-1"
|
||||
status, output = subprocess.getstatusoutput(cmnd)
|
||||
@ -319,7 +323,7 @@ if _RESTORE:
|
||||
print(cmnd)
|
||||
status, output = subprocess.getstatusoutput(cmnd)
|
||||
|
||||
cmnd = 'egrep -l "# kestra.sectorq.eu|# auth.sectorq.eu|# ha.sectorq.eu|# pw.sectorq.eu|# semaphore.sectorq.eu|# sectorq.eu|# gitlab.sectorq.eu|# ha.sectorq.eu" /share/docker_data/nginx/data/nginx/proxy_host/*'
|
||||
cmnd = 'egrep -l "# bazarr.sectorq.eu|# gitea.sectorq.eu|# jf.sectorq.eu|# kestra.sectorq.eu|# auth.sectorq.eu|# ha.sectorq.eu|# pw.sectorq.eu|# semaphore.sectorq.eu|# sectorq.eu|# gitlab.sectorq.eu|# ha.sectorq.eu" /share/docker_data/nginx/data/nginx/proxy_host/*'
|
||||
status, output = subprocess.getstatusoutput(cmnd)
|
||||
print(output.splitlines())
|
||||
for file in output.splitlines():
|
||||
@ -350,18 +354,14 @@ if _RESTORE:
|
||||
now = datetime.datetime.now()
|
||||
ENDTIME = now.strftime("%Y-%m-%d_%H:%M:%S")
|
||||
msg = {"status":"finished","bak_name":app,"start_time":DATETIME,"end_time":ENDTIME,"progress":0}
|
||||
client.connect(broker,1883,10)
|
||||
client.publish(topic, json.dumps(msg),2,True)
|
||||
client.disconnect()
|
||||
send_mqtt_message(msg)
|
||||
|
||||
now = datetime.datetime.now()
|
||||
ENDJOB = now.strftime("%Y-%m-%d_%H:%M:%S")
|
||||
print("Sending finished status")
|
||||
msg = {"mode":_MODE,"status":"finished","bak_name":"complete","start_time":STARTTIME,"end_time":ENDJOB,"progress":0,"used_space":"?"}
|
||||
print(msg)
|
||||
client.connect(broker,1883,10)
|
||||
client.publish(topic_sum, json.dumps(msg),2,True)
|
||||
client.disconnect()
|
||||
send_mqtt_message(msg)
|
||||
|
||||
if _MODE == "auto":
|
||||
cmnd = "ssh root@amd.home.lan 'systemctl suspend &'"
|
||||
@ -384,8 +384,7 @@ if _BACKUP:
|
||||
now = datetime.datetime.now()
|
||||
STARTTIME = now.strftime("%Y-%m-%d_%H:%M:%S")
|
||||
msg = {"mode":_MODE, "status":"started","bak_name":"complete","host":"","cur_job":"","start_time":STARTTIME,"end_time":"in progress","progress":0,"finished":",".join(finished)}
|
||||
client.publish(topic_sum, json.dumps(msg),qos=0, retain=True);
|
||||
client.disconnect()
|
||||
send_mqtt_message(msg)
|
||||
# iterate over files in
|
||||
# that directory
|
||||
|
||||
@ -399,11 +398,8 @@ if _BACKUP:
|
||||
topic = "sectorq/amd/backups"
|
||||
if not backups[host]["jobs"][b]["active"]:
|
||||
print("Backup {} is not active!".format(b))
|
||||
client.connect(broker,1883,60)
|
||||
msg = {"status":"inactive","bak_name":b,"start_time":"inactive","end_time":"inactive","progress":0}
|
||||
|
||||
client.publish(topic, json.dumps(msg),qos=0, retain=True)
|
||||
client.disconnect()
|
||||
send_mqtt_message(msg)
|
||||
continue
|
||||
|
||||
SOURCE_DIR = backups[host]["jobs"][b]["source"]
|
||||
@ -461,6 +457,8 @@ if _BACKUP:
|
||||
status, output = subprocess.getstatusoutput(cmnd)
|
||||
#proc = subprocess.Popen(cmnd,stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE,cwd = "/myapps/",shell=True)
|
||||
|
||||
|
||||
|
||||
cmnd = f"rm -rf {FULL_BACKUP_LATEST}"
|
||||
|
||||
print(cmnd)
|
||||
@ -493,9 +491,7 @@ if _BACKUP:
|
||||
#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)}
|
||||
client.connect(broker,1883,10)
|
||||
client.publish(topic, json.dumps(msg),qos=0, retain=True)
|
||||
client.disconnect()
|
||||
send_mqtt_message(msg)
|
||||
|
||||
print("Getting size of FS")
|
||||
cmnd = "df -h /mnt/raid|awk '{ print $3 }'|tail -1"
|
||||
@ -511,9 +507,7 @@ if _BACKUP:
|
||||
print(msg)
|
||||
|
||||
|
||||
client.connect(broker,1883,10)
|
||||
client.publish(topic_sum, json.dumps(msg),qos=0, retain=True)
|
||||
client.disconnect()
|
||||
send_mqtt_message(msg)
|
||||
|
||||
os.remove(filename.path)
|
||||
# if _MODE == "auto":
|
||||
|
Reference in New Issue
Block a user