From f79b652cb9fbea2e75560b0a899fd16218a5d82e Mon Sep 17 00:00:00 2001 From: wwartana Date: Thu, 29 Jan 2026 23:20:17 +0800 Subject: [PATCH] Fix cleanup crash and disable console --- backup_manager.py | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/backup_manager.py b/backup_manager.py index 8bb5f66..7db33fd 100644 --- a/backup_manager.py +++ b/backup_manager.py @@ -232,18 +232,29 @@ class BackupStrategy(ABC): count = 0 try: - for filename in os.listdir(dest): - filepath = os.path.join(dest, filename) - if os.path.isfile(filepath): - # Check modified time or created time - file_time = os.path.getmtime(filepath) - if file_time < cutoff: - try: + # Recursive scan for YYYY/MM/DD structure + for root, dirs, files in os.walk(dest): + for filename in files: + filepath = os.path.join(root, filename) + try: + # Check modified time + file_time = os.path.getmtime(filepath) + if file_time < cutoff: os.remove(filepath) self.log("Menghapus backup lama: {}".format(filename)) count += 1 - except Exception as e: - self.log("Gagal menghapus {}: {}".format(filename, e)) + except Exception as e: + self.log("Gagal menghapus {}: {}".format(filename, e)) + + # Optional: Remove empty folders after cleanup + for root, dirs, files in os.walk(dest, topdown=False): + for name in dirs: + d_path = os.path.join(root, name) + try: + if not os.listdir(d_path): # Check if empty + os.rmdir(d_path) + except: pass + except Exception as e: self.log("Error saat pembersihan: {}".format(e)) @@ -401,7 +412,7 @@ class MySQLBackup(BackupStrategy): "Letakkan di folder 'sql_tools' di samping ProBackup.exe\n" "atau pastikan sql_tools ada di dalam bundle.") - "atau pastikan sql_tools ada di dalam bundle.") + # Use dated directory target_dest = self._get_dated_dest_dir(dest)