Compare commits

..

4 Commits

Author SHA1 Message Date
fb4acad563 build 2025-08-21 13:00:22 +02:00
a57c73cc74 build 2025-08-21 12:13:54 +02:00
4327d7490b build 2025-08-21 11:50:34 +02:00
c72aa231c7 build 2025-08-21 11:45:53 +02:00

View File

@@ -544,7 +544,7 @@ if _BACKUP:
#cmd = f"rsync -avz --delete {BACKUP_DIR} --link-dest {FULL_BACKUP_LATEST}/ --exclude=\"jellyfin/cache/transcodes\" --exclude=\"gitlab/logs/prometheus\" --exclude=\"home-assistant.log\" --exclude=\"gitlab/logs/*\" --exclude=\"esphome/config/.esphome\" --exclude=\".cache\" --exclude=\".git\" --exclude=\"var_lib_motioneye\" {NEW_BACKUP_DIR}" #cmd = f"rsync -avz --delete {BACKUP_DIR} --link-dest {FULL_BACKUP_LATEST}/ --exclude=\"jellyfin/cache/transcodes\" --exclude=\"gitlab/logs/prometheus\" --exclude=\"home-assistant.log\" --exclude=\"gitlab/logs/*\" --exclude=\"esphome/config/.esphome\" --exclude=\".cache\" --exclude=\".git\" --exclude=\"var_lib_motioneye\" {NEW_BACKUP_DIR}"
#cmd = [ 'rsync', '-avz','--info=progress2', BACKUP_DIR , NEW_BACKUP_DIR] #cmd = [ 'rsync', '-avz','--info=progress2', BACKUP_DIR , NEW_BACKUP_DIR]
cmd = ['rsync', '-avz', '--delete', BACKUP_DIR, '--link-dest', FULL_BACKUP_LATEST, '--exclude="jellyfin/cache/transcodes"', '--exclude=".@__thumb/"', '--exclude="gitlab/logs/prometheus"', '--exclude="home-assistant.log"', '--exclude="gitlab/logs/*"', '--exclude="esphome/config/.esphome"', '--exclude=".cache"', '--exclude=".git"', '--exclude="var_lib_motioneye"', '--exclude="/.esphome/build"', NEW_BACKUP_DIR] cmd = ['rsync', '-avz', '--delete', BACKUP_DIR, '--link-dest', FULL_BACKUP_LATEST, '--exclude="home-assistant_v2.db"', '--exclude="jellyfin/cache/transcodes"', '--exclude=".@__thumb/"', '--exclude="gitlab/logs/prometheus"', '--exclude="home-assistant.log"', '--exclude="gitlab/logs/*"', '--exclude="esphome/config/.esphome"', '--exclude=".cache"', '--exclude=".git"', '--exclude="var_lib_motioneye"', '--exclude="/.esphome/build"', NEW_BACKUP_DIR]
logging.info(" ".join(cmd)) logging.info(" ".join(cmd))
process = subprocess.Popen(cmd, process = subprocess.Popen(cmd,
stdout=subprocess.PIPE) stdout=subprocess.PIPE)
@@ -616,9 +616,9 @@ if _BACKUP:
logging.info("Removing old dirs") logging.info("Removing old dirs")
# input("????") # input("????")
#cmnd = "find {} -maxdepth 1 -type d -mtime +30 -exec rm -rf {{}} \;".format(BACKUP_DIR) #cmnd = "find {} -maxdepth 1 -type d -mtime +30 -exec rm -rf {{}} \;".format(BACKUP_DIR)
cmnd = f"cd {BACKUP_ROOT} find ./ -maxdepth 1 -type d -mmin +30 -exec rm -rf {{}} \\;" #cmnd = f"cd {BACKUP_ROOT} find ./ -maxdepth 1 -type d -mmin +30 -exec rm -rf {{}} \\;"
cmnd = "ls {BACKUP_ROOT}" cmnd = f"ls {BACKUP_ROOT}"
#print(cmnd) #print(cmnd)
@@ -627,21 +627,32 @@ if _BACKUP:
status, output = subprocess.getstatusoutput(cmnd) status, output = subprocess.getstatusoutput(cmnd)
for f in output.splitlines(): for f in output.splitlines():
pattern = r"^[0-9]{4}.*" # regex pattern: string starts with 'abc' pattern = r"^[0-9]{4}.*" # regex pattern: string starts with 'abc'
logging.info(f"Checking {f}")
if re.match(pattern, f): if re.match(pattern, f):
logging.info("Match!") logging.info("Match!")
dt = datetime.datetime.strptime(f, "%Y-%m-%d_%H-%M-%S") dt = datetime.datetime.strptime(f, "%Y-%m-%d_%H-%M-%S")
epoch_time = int(dt.timestamp()) epoch_time = int(dt.timestamp())
now_epoch = int(datetime.datetime.now().timestamp()) now_epoch = int(datetime.datetime.now().timestamp())
x = now_epoch - epoch_time x = now_epoch - epoch_time
logging.info(epoch_time) # Output: 45 # logging.info(epoch_time) # Output: 45
if x > "2592000": if x > 2592000:
dir_path = "{BACKUP_ROOT}/{f}" dir_path = f"{BACKUP_ROOT}/{f}"
logging.info(f"removing {dir_path}") logging.info(f"removing {dir_path}")
#shutil.rmtree(dir_path) shutil.rmtree(dir_path)
else: else:
print("No match.") print("No match.")
cmnd = f"ls {BACKUP_ROOT}|grep _running"
#print(cmnd)
# input("????")
logging.info(f"removing obsolete dirs")
if _EXECUTE:
status, output = subprocess.getstatusoutput(cmnd)
for f in output.splitlines():
dir_path = "{BACKUP_ROOT}/{f}"
logging.info(f"removing {dir_path}")
shutil.rmtree(dir_path)
now = datetime.datetime.now() now = datetime.datetime.now()
ENDTIME = now.strftime("%Y-%m-%d_%H:%M:%S") ENDTIME = now.strftime("%Y-%m-%d_%H:%M:%S")
#msg = {"status":"finished","bak_name":b,"start_time":DATETIME,"end_time":ENDTIME,"progress":0} #msg = {"status":"finished","bak_name":b,"start_time":DATETIME,"end_time":ENDTIME,"progress":0}