fix error on delete backup

This commit is contained in:
2025-09-13 11:34:50 +02:00
parent b3723ccc2f
commit eb970733bc
2 changed files with 26 additions and 24 deletions

View File

@@ -150,12 +150,12 @@ class BackupManager:
base_dest_path, is_system, source_name, is_encrypted)
os.makedirs(profile_path, exist_ok=True)
latest_full_backup_path = self._find_latest_backup(
latest_backup_path = self._find_latest_backup(
profile_path, source_name)
if mode == "incremental" and not latest_full_backup_path:
if mode == "incremental" and not latest_backup_path:
self.logger.log(
f"Mode is incremental, but no full backup found for source '{source_name}'. Forcing full backup.")
f"Mode is incremental, but no previous backup found for source '{source_name}'. Forcing full backup.")
mode = "full"
now = datetime.datetime.now()
@@ -168,9 +168,9 @@ class BackupManager:
rsync_command_parts = [
'rsync', '-aAXHv'] if is_system else ['rsync', '-aLv']
if mode == "incremental" and latest_full_backup_path and not is_dry_run:
if mode == "incremental" and latest_backup_path and not is_dry_run:
rsync_command_parts.append(
f"--link-dest={latest_full_backup_path}")
f"--link-dest={latest_backup_path}")
rsync_command_parts.extend(['--info=progress2'])
if exclude_files:
@@ -413,14 +413,14 @@ class BackupManager:
self.logger.log(
f"Metadata file found for {backup_dir_name} but data directory not found at {full_path}. Skipping.")
continue
profile_name = "system" if is_system else source_name
if not self.encryption_manager.is_mounted(base_dest_path, profile_name):
self.logger.log(
f"Mounting container for profile {profile_name} at {base_dest_path} to check for backup data...")
self.encryption_manager.prepare_encrypted_destination(
base_dest_path, profile_name, is_system, 0, self.app.queue if self.app else None)
if not os.path.isdir(full_path):
self.logger.log(
f"Data directory {full_path} still not found after mount attempt. Skipping.")
@@ -515,26 +515,26 @@ class BackupManager:
def _find_latest_backup(self, profile_path: str, source_name: str) -> Optional[str]:
self.logger.log(
f"Searching for latest full backup for source '{source_name}' in: {profile_path}")
full_backups = []
f"Searching for latest backup for source '{source_name}' in: {profile_path}")
backups = []
if os.path.isdir(profile_path):
pattern = re.compile(
rf"^(\d{{8}}-\d{{6}})_{re.escape(source_name)}_full_(plain|enc)$")
rf"^(\d{{8}}-\d{{6}})_{re.escape(source_name)}_(full|incremental)_(plain|enc)$")
for item in os.listdir(profile_path):
item_path = os.path.join(profile_path, item)
if os.path.isdir(item_path) and pattern.match(item):
full_backups.append(item)
backups.append(item)
if not full_backups:
self.logger.log("No full backups found.")
if not backups:
self.logger.log("No backups found.")
return None
full_backups.sort(reverse=True)
latest_backup_dir = full_backups[0]
backups.sort(reverse=True)
latest_backup_dir = backups[0]
latest_backup_path = os.path.join(profile_path, latest_backup_dir)
self.logger.log(
f"Found latest full backup for --link-dest: {latest_backup_path}")
f"Found latest backup for --link-dest: {latest_backup_path}")
return latest_backup_path
def _create_info_json(self, base_dest_path: str, backup_dir_name: str, source_name: str, backup_type: str, mode: str, size_bytes: int, is_encrypted: bool, based_on: Optional[str] = None, comment: str = ""):
@@ -672,9 +672,9 @@ class BackupManager:
self.logger.log(f"Error loading cron jobs: {e}")
return jobs_list
def start_delete_backup(self, path_to_delete: str, is_encrypted: bool, is_system: bool, base_dest_path: str, queue, password: Optional[str] = None):
def start_delete_backup(self, path_to_delete: str, is_encrypted: bool, is_system: bool, source_name: str, base_dest_path: str, queue, password: Optional[str] = None):
thread = threading.Thread(target=self._run_delete, args=(
path_to_delete, is_encrypted, is_system, base_dest_path, queue, password))
path_to_delete, is_encrypted, is_system, source_name, base_dest_path, queue, password))
thread.daemon = True
thread.start()
@@ -690,14 +690,16 @@ class BackupManager:
profile_name = "system" if is_system else source_name
mount_point = self.encryption_manager.get_mount_point(
base_dest_path, profile_name)
if not self.encryption_manager.is_mounted(base_dest_path, profile_name):
self.logger.log(f"Container for profile {profile_name} not mounted. Mounting for deletion.")
self.logger.log(
f"Container for profile {profile_name} not mounted. Mounting for deletion.")
# Note: mount_for_deletion is not profile-aware yet, we are calling _open_and_mount directly
if not self.encryption_manager._open_and_mount(base_dest_path, profile_name, is_system, password_override=password):
self.logger.log("Failed to unlock container for deletion.")
queue.put(('deletion_complete', False))
return
self.logger.log(
"Failed to unlock container for deletion.")
queue.put(('deletion_complete', False))
return
internal_path_to_delete = os.path.join(
mount_point, os.path.basename(os.path.dirname(path_to_delete)), backup_dir_name)

View File

@@ -134,7 +134,7 @@ class UserBackupContentFrame(ttk.Frame):
if is_encrypted:
password = self.backup_manager.encryption_manager.get_password(
confirm=False)
selected_backup.get('source'), confirm=False)
if not password:
self.actions.logger.log(
"Password entry cancelled, aborting deletion.")