mirror of
https://gitlab.sectorq.eu/jaydee/omv_backup.git
synced 2025-07-01 23:58:33 +02:00
Compare commits
124 Commits
8c53b07cf5
...
main
Author | SHA1 | Date | |
---|---|---|---|
1ecedd7c00 | |||
87c671d23b | |||
97297f0c4e | |||
58e2596d3d | |||
ff736e20f1 | |||
94f5a08920 | |||
3f7a77b7b0 | |||
687ffc828d | |||
f17f1ca372 | |||
d5b114e771 | |||
edb3091b2a | |||
10edb2b533 | |||
3bffbd872d | |||
af5d64200c | |||
95dd8fb52b | |||
45476954cc | |||
386e3ec75c | |||
854f0c828a | |||
06c776ee90 | |||
71d661dfb5 | |||
ca518405ff | |||
a1b4aff656 | |||
b40a7f795e | |||
50d9f18969 | |||
baa26b3a09 | |||
eff8120428 | |||
25151a5776 | |||
82b9f93e13 | |||
6fa3c016b2 | |||
23d32537c7 | |||
607f58ae0a | |||
dce4ccb711 | |||
b66a4598de | |||
3d2d8e5c3d | |||
b12359c373 | |||
cc698871f6 | |||
66867ae717 | |||
9554f194ac | |||
4ea82d55a8 | |||
d855defac0 | |||
a90c1d5589 | |||
5cae7332d5 | |||
e17d538c2b | |||
f9266b0bc9 | |||
7909eadad5 | |||
c5a71ef749 | |||
7a3da9ee7d | |||
ab5ba0e10d | |||
db3d4245d9 | |||
6b522f6cbc | |||
39d16f6f2c | |||
5ed0031208 | |||
fded5b677c | |||
67b73319e0 | |||
9daa539028 | |||
f22b99030b | |||
ac2d7d212e | |||
6a52d29803 | |||
fd99f4ef78 | |||
daeb2901f2 | |||
59f6d1669b | |||
ca9a2d0969 | |||
6ff4833e0b | |||
506e4cc7df | |||
ccf4d16c55 | |||
6acf13de4e | |||
e9b1c18bb7 | |||
6f70dbc83c | |||
2951d204a6 | |||
15e1275c5a | |||
c636e1f2e5 | |||
97ff1a3197 | |||
6bd7d5dde6 | |||
bfefa386a5 | |||
afe5faae8a | |||
047001a93b | |||
8f860f1180 | |||
58c9816677 | |||
665b0b36b4 | |||
987d04fc86 | |||
94bab11c58 | |||
69b2ab1920 | |||
120a2127c4 | |||
341edd4399 | |||
0797e69619 | |||
19d039ec13 | |||
f2d6f3f391 | |||
0307bf4aff | |||
da25006c74 | |||
cded28f0cc | |||
4134d56c98 | |||
99e111d089 | |||
1e0ee17dda | |||
59b8436596 | |||
9d07b227fb | |||
a42a9ac8b7 | |||
c4c8f6421a | |||
62c235ff4c | |||
459a58cdc7 | |||
29f2e7dd95 | |||
703a67f516 | |||
9f7f13e7cb | |||
9c34880ba9 | |||
7eb37d2184 | |||
69a404ccad | |||
6d4602aeaa | |||
a50bdeb9d3 | |||
b7342433bf | |||
41c5628fbb | |||
7fadea9fa7 | |||
16b0e0e7e4 | |||
0082963725 | |||
004a737215 | |||
d795a5e4cd | |||
d9c9b010a9 | |||
a3e804c80d | |||
dd9d7e1241 | |||
134e538b1f | |||
a2f42d41c2 | |||
9e51ed3707 | |||
f03a7362bd | |||
2913f8c5cd | |||
7bafeb227a | |||
2fbe457fde |
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
.gitlab-ci.yml
|
@ -1,9 +1,30 @@
|
|||||||
stages:
|
# This file is a template, and might need editing before it works on your project.
|
||||||
- build
|
# This is a sample GitLab CI/CD configuration file that should run without any modifications.
|
||||||
|
# It demonstrates a basic 3 stage CI/CD pipeline. Instead of real tests or scripts,
|
||||||
|
# it uses echo commands to simulate the pipeline execution.
|
||||||
|
#
|
||||||
|
# A pipeline is composed of independent jobs that run scripts, grouped into stages.
|
||||||
|
# Stages run in sequential order, but jobs within stages run in parallel.
|
||||||
|
#
|
||||||
|
# For more information, see: https://docs.gitlab.com/ee/ci/yaml/#stages
|
||||||
|
#
|
||||||
|
# You can copy and paste this template into a new `.gitlab-ci.yml` file.
|
||||||
|
# You should not add this template to an existing `.gitlab-ci.yml` file by using the `include:` keyword.
|
||||||
|
#
|
||||||
|
# To contribute improvements to CI/CD templates, please follow the Development guide at:
|
||||||
|
# https://docs.gitlab.com/development/cicd/templates/
|
||||||
|
# This specific template is located at:
|
||||||
|
# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Getting-Started.gitlab-ci.yml
|
||||||
|
|
||||||
build_job:
|
stages: # List of stages for jobs, and their order of execution
|
||||||
|
- build
|
||||||
|
|
||||||
|
|
||||||
|
build-job: # This job runs in the build stage, which runs first.
|
||||||
stage: build
|
stage: build
|
||||||
script:
|
script:
|
||||||
- echo "Running build pipeline"
|
- column=":"
|
||||||
|
- echo "${flow_id}"
|
||||||
|
- curl -X POST https://kestra.sectorq.eu/api/v1/executions/webhook/jaydee/ansible-all/${flow_id} -d '{"tag":["setup","omv_backup"],"target":["servers"]}' -H "Content-Type${column} application/json"
|
||||||
|
rules:
|
||||||
|
- if: '$CI_COMMIT_MESSAGE =~ /build/'
|
||||||
|
@ -1,18 +1,52 @@
|
|||||||
import subprocess
|
import subprocess
|
||||||
import requests
|
import requests
|
||||||
import datetime
|
import datetime
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
now = datetime.datetime.now()
|
now = datetime.datetime.now()
|
||||||
|
PASSWORD = "l4c1j4yd33Du5lo"
|
||||||
DATETIME = now.strftime("%Y%m%d%H%M%S")
|
DATETIME = now.strftime("%Y%m%d%H%M%S")
|
||||||
|
os.chdir("/share/docker_data/__backups/")
|
||||||
print("Backup gitlab")
|
print("Backup gitlab")
|
||||||
cmnd = 'docker exec -t gitlab gitlab-backup create SKIP=artifacts,repositories,registry,uploads,builds,pages,lfs,packages,terraform_state'
|
cmnd = 'docker exec -t gitlab gitlab-backup create SKIP=artifacts,repositories,registry,uploads,builds,pages,lfs,packages,terraform_state'
|
||||||
status, output = subprocess.getstatusoutput(cmnd)
|
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")
|
print("Backup nextcloud")
|
||||||
cmnd = 'docker exec --user www-data nextcloud-app-1 php occ maintenance:mode --on'
|
cmnd = 'docker exec --user www-data nextcloud-app-1 php occ maintenance:mode --on'
|
||||||
status, output = subprocess.getstatusoutput(cmnd)
|
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)
|
status, output = subprocess.getstatusoutput(cmnd)
|
||||||
cmnd = "docker exec --user www-data nextcloud-app-1 php occ maintenance:mode --off"
|
cmnd = "docker exec --user www-data nextcloud-app-1 php occ maintenance:mode --off"
|
||||||
status, output = subprocess.getstatusoutput(cmnd)
|
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")
|
print("Backup portainer")
|
||||||
headers = {
|
headers = {
|
||||||
@ -21,7 +55,7 @@ headers = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
json_data = {
|
json_data = {
|
||||||
'password': 'l4c1j4yd33Du5lo',
|
'password': PASSWORD,
|
||||||
}
|
}
|
||||||
|
|
||||||
response = requests.post('https://portainer.sectorq.eu/api/backup', headers=headers, json=json_data, verify=True)
|
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)
|
#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:
|
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)
|
@ -17,9 +17,10 @@ import fnmatch
|
|||||||
import yaml
|
import yaml
|
||||||
import paramiko
|
import paramiko
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
file_path = os.path.realpath(__file__)
|
file_path = os.path.realpath(__file__)
|
||||||
dir_path = os.path.dirname(file_path)
|
dir_path = os.path.dirname(file_path)
|
||||||
VERSION="1.0.3"
|
VERSION="1.0.7"
|
||||||
# print(file_path)
|
# print(file_path)
|
||||||
# print(dir_path)
|
# print(dir_path)
|
||||||
os.chdir(dir_path)
|
os.chdir(dir_path)
|
||||||
@ -216,7 +217,6 @@ if _STOP:
|
|||||||
continue
|
continue
|
||||||
cmnd = f"docker stop {c.split()[-1]}"
|
cmnd = f"docker stop {c.split()[-1]}"
|
||||||
status, running_containers = subprocess.getstatusoutput(cmnd)
|
status, running_containers = subprocess.getstatusoutput(cmnd)
|
||||||
|
|
||||||
if _RESTORE:
|
if _RESTORE:
|
||||||
logging.info("Starting Restore")
|
logging.info("Starting Restore")
|
||||||
print("Starting Restore")
|
print("Starting Restore")
|
||||||
@ -224,8 +224,8 @@ if _RESTORE:
|
|||||||
STARTTIME = now.strftime("%Y-%m-%d_%H:%M:%S")
|
STARTTIME = now.strftime("%Y-%m-%d_%H:%M:%S")
|
||||||
if _APP == "all":
|
if _APP == "all":
|
||||||
_DATE = "latest"
|
_DATE = "latest"
|
||||||
if host == "rpi5.home.lan":
|
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:
|
else:
|
||||||
cmnd = "ssh root@amd.home.lan 'ls /mnt/raid/backup/m-server/docker_data/latest'"
|
cmnd = "ssh root@amd.home.lan 'ls /mnt/raid/backup/m-server/docker_data/latest'"
|
||||||
status, output = subprocess.getstatusoutput(cmnd)
|
status, output = subprocess.getstatusoutput(cmnd)
|
||||||
@ -234,9 +234,6 @@ if _RESTORE:
|
|||||||
#input("????")
|
#input("????")
|
||||||
else:
|
else:
|
||||||
_APP = _APP.split(",")
|
_APP = _APP.split(",")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PROGRESS = 0
|
PROGRESS = 0
|
||||||
topic = "sectorq/amd/restore"
|
topic = "sectorq/amd/restore"
|
||||||
step = 100 / len(_APP)
|
step = 100 / len(_APP)
|
||||||
@ -256,11 +253,11 @@ if _RESTORE:
|
|||||||
if _DATE == "pick":
|
if _DATE == "pick":
|
||||||
cmnd = f"ssh root@amd.home.lan 'ls {BACKUP_DEVICE}/backup/m-server/docker_data'"
|
cmnd = f"ssh root@amd.home.lan 'ls {BACKUP_DEVICE}/backup/m-server/docker_data'"
|
||||||
status, output = subprocess.getstatusoutput(cmnd)
|
status, output = subprocess.getstatusoutput(cmnd)
|
||||||
#print(output)
|
print(output)
|
||||||
dates = output.splitlines()
|
dates = output.splitlines()
|
||||||
n = 1
|
n = 1
|
||||||
for i in dates:
|
for i in dates:
|
||||||
logging.info(f"{n} - {i}" )
|
print(f"{n} - {i}" )
|
||||||
n += 1
|
n += 1
|
||||||
|
|
||||||
ans = input("Pick a backup to restore : ")
|
ans = input("Pick a backup to restore : ")
|
||||||
@ -369,15 +366,19 @@ if _RESTORE:
|
|||||||
#loaded['logo']['icon'] = "/images/morefine2.png"
|
#loaded['logo']['icon'] = "/images/morefine2.png"
|
||||||
logging.info(json.dumps(loaded, indent=2))
|
logging.info(json.dumps(loaded, indent=2))
|
||||||
i = 0
|
i = 0
|
||||||
|
|
||||||
|
|
||||||
for y in loaded:
|
for y in loaded:
|
||||||
logging.info(i)
|
logging.info(i)
|
||||||
logging.info(y)
|
logging.info(y)
|
||||||
|
|
||||||
if "logo" in y:
|
if "logo" in y:
|
||||||
if host == "rpi5.home.lan":
|
if host == "rpi5.home.lan" or host == "rpi5":
|
||||||
loaded[i]['logo']['icon'] = "/images/rpi5.png"
|
loaded[i]['logo']['icon'] = "/images/rpi5.png"
|
||||||
elif host == "nas.home.lan":
|
elif host == "nas.home.lan":
|
||||||
loaded[i]['logo']['icon'] = "/images/qnap_nas.png"
|
loaded[i]['logo']['icon'] = "/images/qnap_nas.png"
|
||||||
|
elif host == "rack.home.lan":
|
||||||
|
loaded[i]['logo']['icon'] = "/images/rack.png"
|
||||||
else:
|
else:
|
||||||
loaded[i]['logo']['icon'] = "/images/morefine2.png"
|
loaded[i]['logo']['icon'] = "/images/morefine2.png"
|
||||||
i+=1
|
i+=1
|
||||||
@ -479,6 +480,8 @@ if _BACKUP:
|
|||||||
if filename.is_file():
|
if filename.is_file():
|
||||||
logging.info(filename.path)
|
logging.info(filename.path)
|
||||||
logging.info(filename.name)
|
logging.info(filename.name)
|
||||||
|
if filename.name == "restore":
|
||||||
|
break
|
||||||
host = filename.name
|
host = filename.name
|
||||||
logging.info("Backup")
|
logging.info("Backup")
|
||||||
for b in backups[host]["jobs"]:
|
for b in backups[host]["jobs"]:
|
||||||
@ -644,7 +647,7 @@ if _BACKUP:
|
|||||||
user = "admin"
|
user = "admin"
|
||||||
cmnd = "/share/Data/__GITLAB/omv_backup/venv/bin/python3 /share/Data/__GITLAB/omv_backup/omv_backup.py -r all"
|
cmnd = "/share/Data/__GITLAB/omv_backup/venv/bin/python3 /share/Data/__GITLAB/omv_backup/omv_backup.py -r all"
|
||||||
else:
|
else:
|
||||||
user = "root"
|
user = "jd"
|
||||||
cmnd = "sudo /myapps/omv_backup.py -r all"
|
cmnd = "sudo /myapps/omv_backup.py -r all"
|
||||||
msg = {"mode":_MODE, "status":"restore","bak_name":"s","host":s,"cur_job":"aaa","start_time":1,"end_time":1,"progress":0,"finished":1,"used_space":1}
|
msg = {"mode":_MODE, "status":"restore","bak_name":"s","host":s,"cur_job":"aaa","start_time":1,"end_time":1,"progress":0,"finished":1,"used_space":1}
|
||||||
logging.info(msg)
|
logging.info(msg)
|
||||||
@ -673,6 +676,10 @@ if _BACKUP:
|
|||||||
for line in iter(ssh_stderr.readline, ""):
|
for line in iter(ssh_stderr.readline, ""):
|
||||||
logger.info(line)
|
logger.info(line)
|
||||||
ssh.close()
|
ssh.close()
|
||||||
|
try:
|
||||||
|
os.remove("/backups/restore")
|
||||||
|
except:
|
||||||
|
pass
|
||||||
# if _MODE == "auto":
|
# if _MODE == "auto":
|
||||||
# hostup = True
|
# hostup = True
|
||||||
# cmnd = "ssh root@omv.home.lan 'systemctl suspend &'"
|
# cmnd = "ssh root@omv.home.lan 'systemctl suspend &'"
|
||||||
|
Reference in New Issue
Block a user