Fix cleanup crash and disable console

This commit is contained in:
2026-01-29 23:20:17 +08:00
parent d15cb8bd82
commit f79b652cb9

View File

@@ -232,18 +232,29 @@ class BackupStrategy(ABC):
count = 0 count = 0
try: try:
for filename in os.listdir(dest): # Recursive scan for YYYY/MM/DD structure
filepath = os.path.join(dest, filename) for root, dirs, files in os.walk(dest):
if os.path.isfile(filepath): for filename in files:
# Check modified time or created time filepath = os.path.join(root, filename)
file_time = os.path.getmtime(filepath) try:
if file_time < cutoff: # Check modified time
try: file_time = os.path.getmtime(filepath)
if file_time < cutoff:
os.remove(filepath) os.remove(filepath)
self.log("Menghapus backup lama: {}".format(filename)) self.log("Menghapus backup lama: {}".format(filename))
count += 1 count += 1
except Exception as e: except Exception as e:
self.log("Gagal menghapus {}: {}".format(filename, 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: except Exception as e:
self.log("Error saat pembersihan: {}".format(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" "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.")
"atau pastikan sql_tools ada di dalam bundle.")
# Use dated directory # Use dated directory
target_dest = self._get_dated_dest_dir(dest) target_dest = self._get_dated_dest_dir(dest)