Solved bug

This commit is contained in:
Kevin Veen-Birkenbach 2023-12-26 19:46:20 +01:00
parent fb2e1df233
commit 3fedf49f4e

View File

@ -80,11 +80,13 @@ def backup_database(container, databases, volume_dir, db_type):
execute_shell_command(backup_command) execute_shell_command(backup_command)
print(f"Database backup for {container} completed.") print(f"Database backup for {container} completed.")
def get_last_backup_dir(versions_dir, volume_name): def get_last_backup_dir(versions_dir, volume_name, current_backup_dir):
"""Get the most recent backup directory for the specified volume.""" """Get the most recent backup directory for the specified volume."""
versions = sorted(os.listdir(versions_dir), reverse=True) versions = sorted(os.listdir(versions_dir), reverse=True)
for version in versions: for version in versions:
backup_dir = os.path.join(versions_dir, version, volume_name, "files") backup_dir = os.path.join(versions_dir, version, volume_name, "files")
# Ignore current backup dir
if backup_dir != current_backup_dir:
if os.path.isdir(backup_dir): if os.path.isdir(backup_dir):
return backup_dir return backup_dir
print(f"No previous backups available for volume: {volume_name}") print(f"No previous backups available for volume: {volume_name}")
@ -96,7 +98,7 @@ def backup_volume(volume_name, volume_dir, versions_dir):
files_rsync_destination_path = os.path.join(volume_dir, "files") files_rsync_destination_path = os.path.join(volume_dir, "files")
pathlib.Path(files_rsync_destination_path).mkdir(parents=True, exist_ok=True) pathlib.Path(files_rsync_destination_path).mkdir(parents=True, exist_ok=True)
last_backup_dir = get_last_backup_dir(versions_dir, volume_name) last_backup_dir = get_last_backup_dir(versions_dir, volume_name, files_rsync_destination_path)
link_dest_option = f"--link-dest='{last_backup_dir}'" if last_backup_dir else "" link_dest_option = f"--link-dest='{last_backup_dir}'" if last_backup_dir else ""
source_dir = f"/var/lib/docker/volumes/{volume_name}/_data/" source_dir = f"/var/lib/docker/volumes/{volume_name}/_data/"