mirror of
https://gitlab.sectorq.eu/jaydee/omv_backup.git
synced 2025-07-01 15:48:33 +02:00
Compare commits
10 Commits
edb3091b2a
...
main
Author | SHA1 | Date | |
---|---|---|---|
1ecedd7c00 | |||
87c671d23b | |||
97297f0c4e | |||
58e2596d3d | |||
ff736e20f1 | |||
94f5a08920 | |||
3f7a77b7b0 | |||
687ffc828d | |||
f17f1ca372 | |||
d5b114e771 |
@ -1,18 +1,52 @@
|
||||
import subprocess
|
||||
import requests
|
||||
import datetime
|
||||
import os
|
||||
import shutil
|
||||
now = datetime.datetime.now()
|
||||
PASSWORD = "l4c1j4yd33Du5lo"
|
||||
DATETIME = now.strftime("%Y%m%d%H%M%S")
|
||||
os.chdir("/share/docker_data/__backups/")
|
||||
print("Backup gitlab")
|
||||
cmnd = 'docker exec -t gitlab gitlab-backup create SKIP=artifacts,repositories,registry,uploads,builds,pages,lfs,packages,terraform_state'
|
||||
status, output = subprocess.getstatusoutput(cmnd)
|
||||
allfiles = os.listdir("/share/docker_data/gitlab/data/backups/")
|
||||
for f in allfiles:
|
||||
shutil.move(f"/share/docker_data/gitlab/data/backups/{f}", "/share/docker_data/__backups/")
|
||||
|
||||
|
||||
print("Backup nextcloud")
|
||||
cmnd = 'docker exec --user www-data nextcloud-app-1 php occ maintenance:mode --on'
|
||||
status, output = subprocess.getstatusoutput(cmnd)
|
||||
cmnd = f"docker exec nextcloud-db-1 sh -c 'exec mysqldump --single-transaction -h localhost -u nextcloud -pl4c1j4yd33Du5lo nextcloud' > /share/docker_data/__backups/nextcloudDB_{DATETIME}.sql"
|
||||
cmnd = f"docker exec nextcloud-db-1 sh -c 'exec mysqldump --single-transaction -h localhost -u nextcloud -p{PASSWORD} nextcloud' > /share/docker_data/__backups/nextcloudDB_{DATETIME}.sql"
|
||||
status, output = subprocess.getstatusoutput(cmnd)
|
||||
cmnd = "docker exec --user www-data nextcloud-app-1 php occ maintenance:mode --off"
|
||||
status, output = subprocess.getstatusoutput(cmnd)
|
||||
cmnd = f"zip -P {PASSWORD} nextcloudDB_{DATETIME}.sql.zip nextcloudDB_{DATETIME}.sql"
|
||||
status, output = subprocess.getstatusoutput(cmnd)
|
||||
os.remove(f"nextcloudDB_{DATETIME}.sql")
|
||||
|
||||
print("Backup Bookstack")
|
||||
cmnd = f"docker exec bookstack-db-1 sh -c 'exec mysqldump --single-transaction -h localhost -u bookstack -p{PASSWORD} bookstackapp' > /share/docker_data/__backups/bookstack_{DATETIME}.sql"
|
||||
status, output = subprocess.getstatusoutput(cmnd)
|
||||
cmnd = f"zip -P {PASSWORD} bookstack_{DATETIME}.sql.zip bookstack_{DATETIME}.sql"
|
||||
status, output = subprocess.getstatusoutput(cmnd)
|
||||
os.remove(f"bookstack_{DATETIME}.sql")
|
||||
|
||||
print("Backup Kestra")
|
||||
cmnd = f"docker exec kestra-postgres-1 sh -c 'pg_dump -h localhost -p 5432 -U kestra -d kestra' > /share/docker_data/__backups/kestra_{DATETIME}.sql"
|
||||
status, output = subprocess.getstatusoutput(cmnd)
|
||||
cmnd = f"zip -P {PASSWORD} kestra_{DATETIME}.sql.zip kestra_{DATETIME}.sql"
|
||||
status, output = subprocess.getstatusoutput(cmnd)
|
||||
os.remove(f"kestra_{DATETIME}.sql")
|
||||
|
||||
print("Backup Authentik")
|
||||
cmnd = f"docker exec authentik-postgresql-1 sh -c 'pg_dump -h localhost -p 5432 -U authentik -d authentik' > /share/docker_data/__backups/authentik_{DATETIME}.sql"
|
||||
status, output = subprocess.getstatusoutput(cmnd)
|
||||
cmnd = f"zip -P {PASSWORD} authentik_{DATETIME}.sql.zip authentik_{DATETIME}.sql"
|
||||
status, output = subprocess.getstatusoutput(cmnd)
|
||||
os.remove(f"authentik_{DATETIME}.sql")
|
||||
|
||||
|
||||
print("Backup portainer")
|
||||
headers = {
|
||||
@ -21,7 +55,7 @@ headers = {
|
||||
}
|
||||
|
||||
json_data = {
|
||||
'password': 'l4c1j4yd33Du5lo',
|
||||
'password': PASSWORD,
|
||||
}
|
||||
|
||||
response = requests.post('https://portainer.sectorq.eu/api/backup', headers=headers, json=json_data, verify=True)
|
||||
@ -32,4 +66,8 @@ response = requests.post('https://portainer.sectorq.eu/api/backup', headers=head
|
||||
#response = requests.post('https://portainer.sectorq.eu/api/backup', headers=headers, data=data, verify=False)
|
||||
|
||||
with open(f'/share/docker_data/__backups/portainer_snapshot_{DATETIME}.tar.gz', 'wb') as f:
|
||||
f.write(response.content)
|
||||
f.write(response.content)
|
||||
os.chdir("/share/docker_data/__backups/")
|
||||
print("Remove Old Files")
|
||||
cmnd = f" find ./ -maxdepth 1 -type f -mtime +15 -exec rm -f {{}} \\;"
|
||||
status, output = subprocess.getstatusoutput(cmnd)
|
@ -20,7 +20,7 @@ import numpy as np
|
||||
|
||||
file_path = os.path.realpath(__file__)
|
||||
dir_path = os.path.dirname(file_path)
|
||||
VERSION="1.0.6"
|
||||
VERSION="1.0.7"
|
||||
# print(file_path)
|
||||
# print(dir_path)
|
||||
os.chdir(dir_path)
|
||||
@ -225,7 +225,7 @@ if _RESTORE:
|
||||
if _APP == "all":
|
||||
_DATE = "latest"
|
||||
if host == "rpi5.home.lan" or host == "rpi5":
|
||||
_APP = ["nginx","ha","gitea","gitlab","mailu","bitwarden","esphome","grafana","ingluxdb","kestra","matter-server","mosquitto","octoprint","octoprint2","pihole","unify_block","webhub","homepage","watchtower"]
|
||||
_APP = ["__backups", "nginx","ha","gitea","gitlab","mailu","bitwarden","esphome","grafana","ingluxdb","kestra","matter-server","mosquitto","octoprint","octoprint2","pihole","unify_block","webhub","homepage","watchtower"]
|
||||
else:
|
||||
cmnd = "ssh root@amd.home.lan 'ls /mnt/raid/backup/m-server/docker_data/latest'"
|
||||
status, output = subprocess.getstatusoutput(cmnd)
|
||||
@ -253,11 +253,11 @@ if _RESTORE:
|
||||
if _DATE == "pick":
|
||||
cmnd = f"ssh root@amd.home.lan 'ls {BACKUP_DEVICE}/backup/m-server/docker_data'"
|
||||
status, output = subprocess.getstatusoutput(cmnd)
|
||||
#print(output)
|
||||
print(output)
|
||||
dates = output.splitlines()
|
||||
n = 1
|
||||
for i in dates:
|
||||
logging.info(f"{n} - {i}" )
|
||||
print(f"{n} - {i}" )
|
||||
n += 1
|
||||
|
||||
ans = input("Pick a backup to restore : ")
|
||||
|
Reference in New Issue
Block a user