mirror of
https://gitlab.sectorq.eu/jaydee/omv_backup.git
synced 2025-09-13 20:20:11 +02:00
build
This commit is contained in:
@@ -478,12 +478,20 @@ def restore_job(_APP):
|
|||||||
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)
|
||||||
|
|
||||||
def backup_job(server):
|
def backup_job(pl):
|
||||||
client2 = mqtt.Client()
|
client2 = mqtt.Client()
|
||||||
client2.username_pw_set("jaydee", "jaydee1")
|
client2.username_pw_set("jaydee", "jaydee1")
|
||||||
client2.connect("mqtt.home.lan",1883,60)
|
client2.connect("mqtt.home.lan",1883,60)
|
||||||
logging.info(f'starting backup job')
|
logging.info(f'starting backup job')
|
||||||
|
|
||||||
|
server = pl["host"]
|
||||||
|
if pl["mode"] == "dry":
|
||||||
|
_DRYRUN = True
|
||||||
|
logging.info("Dry run active")
|
||||||
|
else:
|
||||||
|
_DRYRUN = False
|
||||||
|
logging.info("Full mode active")
|
||||||
|
|
||||||
finished = []
|
finished = []
|
||||||
now = datetime.datetime.now()
|
now = datetime.datetime.now()
|
||||||
STARTTIME = now.strftime("%Y-%m-%d_%H:%M:%S")
|
STARTTIME = now.strftime("%Y-%m-%d_%H:%M:%S")
|
||||||
@@ -554,9 +562,9 @@ def backup_job(server):
|
|||||||
progress = 0
|
progress = 0
|
||||||
cmd = ['rsync', '-avz', '--delete', BACKUP_DIR, '--link-dest', FULL_BACKUP_LATEST, '--exclude-from=/myapps/exclude.txt', NEW_BACKUP_DIR]
|
cmd = ['rsync', '-avz', '--delete', BACKUP_DIR, '--link-dest', FULL_BACKUP_LATEST, '--exclude-from=/myapps/exclude.txt', NEW_BACKUP_DIR]
|
||||||
logging.info(" ".join(cmd))
|
logging.info(" ".join(cmd))
|
||||||
|
if not _DRYRUN:
|
||||||
process = subprocess.Popen(cmd,
|
process = subprocess.Popen(cmd,
|
||||||
stdout=subprocess.PIPE)
|
stdout=subprocess.PIPE)
|
||||||
|
|
||||||
while process.poll() is None:
|
while process.poll() is None:
|
||||||
line = process.stdout.readline().decode("utf-8").split("/")
|
line = process.stdout.readline().decode("utf-8").split("/")
|
||||||
print(line[0])
|
print(line[0])
|
||||||
@@ -589,7 +597,7 @@ def backup_job(server):
|
|||||||
logging.info("Creating new latest link")
|
logging.info("Creating new latest link")
|
||||||
#print(cmnd)
|
#print(cmnd)
|
||||||
# input("????")
|
# input("????")
|
||||||
if _EXECUTE:
|
if not _DRYRUN:
|
||||||
status, output = subprocess.getstatusoutput(cmnd)
|
status, output = subprocess.getstatusoutput(cmnd)
|
||||||
|
|
||||||
#Remove old
|
#Remove old
|
||||||
@@ -597,7 +605,7 @@ def backup_job(server):
|
|||||||
|
|
||||||
cmnd = f"ls {BACKUP_ROOT}"
|
cmnd = f"ls {BACKUP_ROOT}"
|
||||||
|
|
||||||
if _EXECUTE:
|
if not _DRYRUN:
|
||||||
status, output = subprocess.getstatusoutput(cmnd)
|
status, output = subprocess.getstatusoutput(cmnd)
|
||||||
for f in output.splitlines():
|
for f in output.splitlines():
|
||||||
pattern = r"^[0-9]{4}-[0-9]{2}-[0-9]{2}_[0-9]{2}-[0-9]{2}-[0-9]{2}$" # regex pattern: string starts with 'abc'
|
pattern = r"^[0-9]{4}-[0-9]{2}-[0-9]{2}_[0-9]{2}-[0-9]{2}-[0-9]{2}$" # regex pattern: string starts with 'abc'
|
||||||
@@ -619,7 +627,7 @@ def backup_job(server):
|
|||||||
|
|
||||||
cmnd = f"ls {BACKUP_ROOT}|grep _running"
|
cmnd = f"ls {BACKUP_ROOT}|grep _running"
|
||||||
logging.info(f"removing obsolete dirs")
|
logging.info(f"removing obsolete dirs")
|
||||||
if _EXECUTE:
|
if not _DRYRUN:
|
||||||
status, output = subprocess.getstatusoutput(cmnd)
|
status, output = subprocess.getstatusoutput(cmnd)
|
||||||
for f in output.splitlines():
|
for f in output.splitlines():
|
||||||
dir_path = f"{BACKUP_ROOT}/{f}"
|
dir_path = f"{BACKUP_ROOT}/{f}"
|
||||||
@@ -650,11 +658,13 @@ def backup_job(server):
|
|||||||
topic = "sectorq/backups/start"
|
topic = "sectorq/backups/start"
|
||||||
logging.info(f"LALA : {topic}")
|
logging.info(f"LALA : {topic}")
|
||||||
client2.publish(topic, "finished",qos=0, retain=True)
|
client2.publish(topic, "finished",qos=0, retain=True)
|
||||||
|
time.sleep(1)
|
||||||
client2.publish(topic, "finished2",qos=0, retain=True)
|
client2.publish(topic, "finished2",qos=0, retain=True)
|
||||||
client2.disconnect()
|
client2.disconnect()
|
||||||
#return "finished"
|
#return "finished"
|
||||||
|
|
||||||
|
if _DRYRUN:
|
||||||
|
return
|
||||||
topic = "sectorq/amd/restore"
|
topic = "sectorq/amd/restore"
|
||||||
for s in servers:
|
for s in servers:
|
||||||
logging.info(f"Restoring {s}")
|
logging.info(f"Restoring {s}")
|
||||||
@@ -752,20 +762,21 @@ def handle_payload(payload):
|
|||||||
pl = json.loads(payload)
|
pl = json.loads(payload)
|
||||||
except:
|
except:
|
||||||
pl = payload
|
pl = payload
|
||||||
logging.info(pl)
|
logging.debug(pl)
|
||||||
return
|
|
||||||
|
|
||||||
if payload == 'm-server':
|
if "host" in pl:
|
||||||
|
if pl["host"] == 'm-server':
|
||||||
logging.info("💡 Starting backup job")
|
logging.info("💡 Starting backup job")
|
||||||
backup_job(payload)
|
backup_job(pl)
|
||||||
logging.info(f"💡 Finished backup job")
|
logging.info(f"💡 Finished backup job")
|
||||||
elif payload == 'nas':
|
elif pl["host"] == 'nas':
|
||||||
logging.info("💡 Starting backup job")
|
logging.info("💡 Starting backup job")
|
||||||
backup_job(payload)
|
backup_job(pl)
|
||||||
logging.info(f"💡 Finished backup job")
|
logging.info(f"💡 Finished backup job")
|
||||||
else:
|
else:
|
||||||
logging.error(f"⚠️ Unknown command: {payload}")
|
logging.error(f"⚠️ Unknown command: {pl}")
|
||||||
|
else:
|
||||||
|
logging.error(f"⚠️ Wrong payload: {pl}")
|
||||||
# Callback when connected
|
# Callback when connected
|
||||||
def on_connect(client, userdata, flags, rc):
|
def on_connect(client, userdata, flags, rc):
|
||||||
if rc == 0:
|
if rc == 0:
|
||||||
|
Reference in New Issue
Block a user