mirror of
https://gitlab.sectorq.eu/jaydee/omv_backup.git
synced 2025-07-02 08:08:32 +02:00
lala
This commit is contained in:
@ -12,6 +12,7 @@ import os
|
||||
import re
|
||||
import platform
|
||||
import requests
|
||||
import fnmatch
|
||||
from wakeonlan import send_magic_packet
|
||||
pid = os.getpid()
|
||||
|
||||
@ -63,6 +64,7 @@ for o, a in opts:
|
||||
elif o in ("-r", "--restore"):
|
||||
_RESTORE = True
|
||||
_APP = a
|
||||
print("RESTORE")
|
||||
elif o in ("-b", "--backup"):
|
||||
_BACKUP = True
|
||||
elif o in ("-d", "--dry"):
|
||||
@ -163,8 +165,9 @@ while not is_port_open(BACKUP_HOST, port):
|
||||
print(f"Port {port} on {BACKUP_HOST} is open.")
|
||||
|
||||
print("Starting")
|
||||
|
||||
print(_RESTORE)
|
||||
if _RESTORE:
|
||||
print("Starting Restore")
|
||||
if _APP == "all":
|
||||
_APP = ["nginx","ha","gitlab","mailu","bitwarden","esphome","grafana","ingluxdb","kestra","matter-server","mosquitto","octoprint","octoprint2","pihole","unify_block","webhub"]
|
||||
else:
|
||||
@ -179,11 +182,16 @@ if _RESTORE:
|
||||
client.publish(topic, json.dumps(msg))
|
||||
client.disconnect()
|
||||
now = datetime.datetime.now()
|
||||
DATETIME = now.strftime("%Y-%m-%d_%H-%M-%S")
|
||||
BACKUP_HOST = "root@omv.home.lan"
|
||||
BACKUP_DEVICE = "/srv/dev-disk-by-uuid-2f843500-95b6-43b0-bea1-9b67032989b8"
|
||||
BACKUP_DIR = f"/backup/{host}"
|
||||
if app == "fail2ban":
|
||||
print("?>?????")
|
||||
NEW_BACKUP_DIR = f"/backup/m-server/fail2ban/latest/"
|
||||
SOURCE_DIR = f"/etc/fail2ban"
|
||||
else:
|
||||
NEW_BACKUP_DIR = f"/backup/m-server/docker_data/latest/{app}"
|
||||
DATETIME = now.strftime("%Y-%m-%d_%H-%M-%S")
|
||||
SOURCE_DIR = f"/share/docker_data/"
|
||||
if _FIRST:
|
||||
BACKUP_PATH="{}/initial".format(BACKUP_DIR)
|
||||
@ -245,6 +253,19 @@ if _RESTORE:
|
||||
print("Start docker")
|
||||
cmnd = "docker start heimdall"
|
||||
status, output = subprocess.getstatusoutput(cmnd)
|
||||
if app == "fail2ban":
|
||||
print("Stopping docker")
|
||||
cmnd = f"rsync -avz --delete rsync://{BACKUP_HOST}{NEW_BACKUP_DIR} {SOURCE_DIR}"
|
||||
ans = "y"
|
||||
print(cmnd)
|
||||
print("Sync files")
|
||||
if _TEST:
|
||||
ans = input("continue?") or "n"
|
||||
if ans == "y" and _EXECUTE:
|
||||
status, output = subprocess.getstatusoutput(cmnd)
|
||||
print("Start docker")
|
||||
cmnd = "docker start heimdall"
|
||||
status, output = subprocess.getstatusoutput(cmnd)
|
||||
elif app == "nginx":
|
||||
print("Stopping docker")
|
||||
cmnd = "docker stop nginx-app-1"
|
||||
@ -314,6 +335,22 @@ if _RESTORE:
|
||||
|
||||
|
||||
if _BACKUP:
|
||||
|
||||
while True:
|
||||
directory = '/backups/'
|
||||
count = len(fnmatch.filter(os.listdir(directory), '*.*'))
|
||||
print('File Count:', count)
|
||||
time.sleep(10)
|
||||
continue
|
||||
|
||||
|
||||
|
||||
# iterate over files in
|
||||
# that directory
|
||||
for filename in os.scandir(directory):
|
||||
if filename.is_file():
|
||||
|
||||
print(filename.path)
|
||||
print("Backup")
|
||||
for b in backups[host]:
|
||||
topic = "sectorq/omv/backups/{}".format(b.lower())
|
||||
|
Reference in New Issue
Block a user