This commit is contained in:
2025-02-24 01:05:33 +01:00
parent cb39f6f671
commit 320b571cc1

View File

@ -49,16 +49,17 @@ mqtt_username = 'jaydee'
mqtt_password = 'jaydee1'
print("1")
try:
opts, args = getopt.getopt(sys.argv[1:], "amftDr:bd:", ["command=", "help", "output="])
opts, args = getopt.getopt(sys.argv[1:], "amftDr:bd:sSO", ["command=", "help", "output="])
except getopt.GetoptError as err:
#usage()
sys.exit(2)
output = None
# QJ : getopts
_MODE = "manual"
_FIRST = _TEST = _RESTORE = _BACKUP = False
_FIRST = _TEST = _RESTORE = _BACKUP = _SYNC = _START = _STOP = False
_EXECUTE = True
_DATE = "pick"
for o, a in opts:
if o == "-a":
_MODE = "auto"
@ -70,6 +71,12 @@ for o, a in opts:
_DATE = a
elif o in ("-t", "--test"):
_TEST = True
elif o in ("-s", "--sync"):
_SYNC = True
elif o in ("-S", "--start"):
_START = True
elif o in ("-O", "--stop"):
_STOP = True
elif o in ("-r", "--restore"):
_RESTORE = True
_APP = a
@ -106,7 +113,7 @@ backups = {
}
},
"m-server":{
"login": "jd@m-server.home.lan",
"login": "root@m-server.home.lan",
"jobs": {
"docker_data":{
"source":"/share/docker_data/",
@ -143,11 +150,39 @@ hm = socket.gethostbyaddr(BACKUP_HOST)
print("Starting")
print(_RESTORE)
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"]
cmnd = f"curl -H 'Authorization: Bearer l4c1j4yd33Du5lo' 192.168.77.238:8094/v1/update"
print(cmnd)
status, output = subprocess.getstatusoutput(cmnd)
if _START:
for c in containers:
cmnd = f"docker start {c}"
print(cmnd)
status, output = subprocess.getstatusoutput(cmnd)
if _STOP:
cmnd = "docker ps"
status, running_containers = subprocess.getstatusoutput(cmnd)
print(running_containers)
for c in running_containers.splitlines():
print(c.split()[-1])
if c.split()[-1] == "watchtower-watchtower-1":
continue
cmnd = f"docker stop {c.split()[-1]}"
status, running_containers = subprocess.getstatusoutput(cmnd)
if _RESTORE:
print("Starting Restore")
now = datetime.datetime.now()
STARTTIME = now.strftime("%Y-%m-%d_%H:%M:%S")
if _APP == "all":
_DATE = "latest"
_APP = ["nginx","ha","gitlab","mailu","bitwarden","esphome","grafana","ingluxdb","kestra","matter-server","mosquitto","octoprint","octoprint2","pihole","unify_block","webhub"]
else:
_APP = _APP.split(",")
@ -165,21 +200,21 @@ if _RESTORE:
BACKUP_HOST = f"jd@omv.home.lan"
BACKUP_DEVICE = "/srv/dev-disk-by-uuid-2f843500-95b6-43b0-bea1-9b67032989b8"
BACKUP_DIR = f"/backup/{host}"
if _DATE == "pick":
cmnd = "ssh root@omv.home.lan 'du --max-depth=1 /srv/dev-disk-by-uuid-2f843500-95b6-43b0-bea1-9b67032989b8/backup/m-server/docker_data'"
cmnd = "ssh root@omv.home.lan 'ls /srv/dev-disk-by-uuid-2f843500-95b6-43b0-bea1-9b67032989b8/backup/m-server/docker_data'"
status, output = subprocess.getstatusoutput(cmnd)
#print(output)
dates = output.splitlines()
n = 1
for i in dates:
s = i.split()
print(f"{n} - {s[1]} / {s[0]}" )
print(f"{n} - {i}" )
n += 1
ans = input("Pick a backup to restore : ")
d = dates[int(ans) - 1]
_DATE = d.split()[1]
_DATE = dates[int(ans) - 1]
if app == "fail2ban":
print("?>?????")
@ -231,8 +266,8 @@ if _RESTORE:
cmnd = f"sqlite3 /share/docker_data/heimdall/config/www/app.sqlite \"UPDATE items SET url = '{contents}' WHERE title = '{e}'\""
print(cmnd)
status, output = subprocess.getstatusoutput(cmnd)
cmnd = "docker start heimdall"
status, output = subprocess.getstatusoutput(cmnd)
# cmnd = "docker start heimdall"
# status, output = subprocess.getstatusoutput(cmnd)
if app == "ha":
print("Stopping docker")
cmnd = "docker stop heimdall"
@ -246,8 +281,8 @@ if _RESTORE:
if ans == "y" and _EXECUTE:
status, output = subprocess.getstatusoutput(cmnd)
print("Start docker")
cmnd = "docker start heimdall"
status, output = subprocess.getstatusoutput(cmnd)
# 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}"
@ -259,8 +294,8 @@ if _RESTORE:
if ans == "y" and _EXECUTE:
status, output = subprocess.getstatusoutput(cmnd)
print("Start docker")
cmnd = "docker start heimdall"
status, output = subprocess.getstatusoutput(cmnd)
# cmnd = "docker start heimdall"
# status, output = subprocess.getstatusoutput(cmnd)
elif app == "nginx":
print("Stopping docker")
cmnd = "docker stop nginx-app-1"
@ -296,8 +331,8 @@ if _RESTORE:
f.close()
status, output = subprocess.getstatusoutput(cmnd)
print("Starting docker")
cmnd = "docker start nginx-app-1"
status, output = subprocess.getstatusoutput(cmnd)
# cmnd = "docker start nginx-app-1"
# status, output = subprocess.getstatusoutput(cmnd)
else:
cmnd = f"rsync -avz --delete rsync://{BACKUP_HOST}{NEW_BACKUP_DIR} {SOURCE_DIR}"
ans = "y"