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
try:
for filename in os.listdir(dest):
filepath = os.path.join(dest, filename)
if os.path.isfile(filepath):
# Check modified time or created time
# 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:
try:
os.remove(filepath)
self.log("Menghapus backup lama: {}".format(filename))
count += 1
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)