mirror of
https://gitlab.sectorq.eu/jaydee/omv_backup.git
synced 2025-09-13 20:20:11 +02:00
Compare commits
14 Commits
571219881d
...
main
Author | SHA1 | Date | |
---|---|---|---|
122ef64ad7 | |||
99f673996e | |||
68e23da03b | |||
1c30fb9995 | |||
b94b61ba5d | |||
26c3245cf3 | |||
1510dc2e8d | |||
d949188a34 | |||
298c9aee23 | |||
808f92c4d1 | |||
43f6d2abcb | |||
81c7ead7b2 | |||
cd818da774 | |||
a1dfbd664c |
@@ -11,4 +11,5 @@ var_lib_motioneye/*
|
||||
*/.esphome/build/*
|
||||
nextcloud/mariadb/*
|
||||
zabbix-server/postgres-data/*
|
||||
gitea-runner/*
|
||||
gitea-runner/*
|
||||
immich/library/*
|
@@ -31,7 +31,7 @@ def signal_handler(sig, frame):
|
||||
signal.signal(signal.SIGINT, signal_handler)
|
||||
file_path = os.path.realpath(__file__)
|
||||
dir_path = os.path.dirname(file_path)
|
||||
VERSION="1.0.9"
|
||||
VERSION="1.0.10"
|
||||
# print(file_path)
|
||||
# print(dir_path)
|
||||
os.chdir(dir_path)
|
||||
@@ -110,7 +110,6 @@ for o, a in opts:
|
||||
elif o in ("-r", "--restore"):
|
||||
_RESTORE = True
|
||||
_APP = a
|
||||
print("RESTORE")
|
||||
elif o in ("-D", "--dry"):
|
||||
_EXECUTE = False
|
||||
elif o in ("-T", "--dry"):
|
||||
@@ -241,9 +240,12 @@ if _STOP:
|
||||
cmnd = f"docker stop {c.split()[-1]}"
|
||||
status, running_containers = subprocess.getstatusoutput(cmnd)
|
||||
def restore_job(_APP):
|
||||
#global VERSION
|
||||
logging.info("Starting Restore")
|
||||
print(f"Starting restore : {VERSION}")
|
||||
now = datetime.datetime.now()
|
||||
STARTTIME = now.strftime("%Y-%m-%d_%H:%M:%S")
|
||||
_DATE = "pick"
|
||||
if _APP == "all":
|
||||
_DATE = "latest"
|
||||
if host == "rpi5.home.lan" or host == "rpi5":
|
||||
@@ -256,6 +258,7 @@ def restore_job(_APP):
|
||||
#input("????")
|
||||
else:
|
||||
_APP = _APP.split(",")
|
||||
|
||||
PROGRESS = 0
|
||||
topic = "sectorq/amd/restore"
|
||||
step = 100 / len(_APP)
|
||||
@@ -277,7 +280,7 @@ def restore_job(_APP):
|
||||
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:
|
||||
@@ -600,7 +603,7 @@ def backup_job(pl):
|
||||
#logging.info(cmnd)
|
||||
logging.info("Removing latest link")
|
||||
# input("????")
|
||||
if _EXECUTE:
|
||||
if not _DRYRUN:
|
||||
status, output = subprocess.getstatusoutput(cmnd)
|
||||
if _FIRST:
|
||||
cmnd = f"cd {BACKUP_ROOT}; ln -s initial latest"
|
||||
@@ -636,6 +639,50 @@ def backup_job(pl):
|
||||
shutil.rmtree(dir_path)
|
||||
else:
|
||||
print("No match.")
|
||||
if not _DRYRUN:
|
||||
logging.info(f"Clearing multiple days")
|
||||
multiple_per_day = {}
|
||||
to_remove = []
|
||||
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'
|
||||
|
||||
if re.match(pattern, f):
|
||||
cday = f.split("_")[0]
|
||||
if cday in multiple_per_day:
|
||||
multiple_per_day[cday].append(f)
|
||||
else:
|
||||
multiple_per_day[cday] = [f]
|
||||
|
||||
|
||||
|
||||
|
||||
# # logging.info("Match!")
|
||||
# dt = datetime.datetime.strptime(f, "%Y-%m-%d_%H-%M-%S")
|
||||
# epoch_time = int(dt.timestamp())
|
||||
# now_epoch = int(datetime.datetime.now().timestamp())
|
||||
|
||||
|
||||
# x = now_epoch - epoch_time
|
||||
# # logging.info(epoch_time) # Output: 45
|
||||
# if x > 2592000:
|
||||
# dir_path = f"{BACKUP_ROOT}/{f}"
|
||||
# logging.info(f"removing {dir_path}")
|
||||
# shutil.rmtree(dir_path)
|
||||
else:
|
||||
print("No match.")
|
||||
logging.info(f"Clearing multiple days: {multiple_per_day}")
|
||||
for f in multiple_per_day:
|
||||
logging.info(f"Looping multiple_per_day : {f}")
|
||||
if len(multiple_per_day[f]) > 1:
|
||||
last = multiple_per_day[f][-1]
|
||||
multiple_per_day[f].pop()
|
||||
logging.info(f"Last from day: {last}")
|
||||
for d in multiple_per_day[f]:
|
||||
logging.info(f"Looping multiple_per_day : {f} : {d}")
|
||||
dir_path = f"{BACKUP_ROOT}/{d}"
|
||||
logging.info(f"removing {dir_path}")
|
||||
shutil.rmtree(dir_path)
|
||||
|
||||
|
||||
cmnd = f"ls {BACKUP_ROOT}|grep _running"
|
||||
logging.info(f"removing obsolete dirs")
|
||||
|
Reference in New Issue
Block a user