Compare commits

...

5 Commits

2 changed files with 26 additions and 13 deletions

View File

@ -217,7 +217,10 @@ def is_image_ignored(container):
return False return False
def backup_with_containers_paused(volume_name, volume_dir, containers, shutdown): def backup_with_containers_paused(volume_name, volume_dir, containers, shutdown):
stop_containers(containers) if containers:
stop_containers(containers)
else:
print(f"{volume_name} has no containers to stop. Skipped.")
backup_volume(volume_name, volume_dir) backup_volume(volume_name, volume_dir)
# Just restart containers if shutdown is false # Just restart containers if shutdown is false
@ -281,9 +284,6 @@ def main():
for volume_name in volume_names: for volume_name in volume_names:
print(f'Start backup routine for volume: {volume_name}') print(f'Start backup routine for volume: {volume_name}')
containers = execute_shell_command(f"docker ps --filter volume=\"{volume_name}\" --format '{{{{.Names}}}}'") containers = execute_shell_command(f"docker ps --filter volume=\"{volume_name}\" --format '{{{{.Names}}}}'")
if not containers:
print('Skipped due to no running containers using this volume.')
continue
if args.everything: if args.everything:
backup_everything(volume_name, containers, args.shutdown) backup_everything(volume_name, containers, args.shutdown)
else: else:

View File

@ -24,19 +24,32 @@ backup_sql="/$backup_folder/sql/$database_name.backup.sql"
# DATABASE RECOVERY # DATABASE RECOVERY
if [ -f "$backup_sql" ]; then if [ ! -z "$database_type" ]; then
if [ -n "$database_container" ] && [ -n "$database_password" ] && [ -n "$database_name" ]; then if [ "$database_type" = "postgres" ]; then
echo "recover mysql dump" if [ -n "$database_container" ] && [ -n "$database_password" ] && [ -n "$database_name" ]; then
cat "$backup_sql" | docker exec -i "$database_container" mariadb -u "$database_user" --password="$database_password" "$database_name" echo "Recover PostgreSQL dump"
if [ $? -ne 0 ]; then export PGPASSWORD="$database_password"
echo "ERROR: Failed to recover mysql dump" cat "$backup_sql" | docker exec -i "$database_container" psql -v ON_ERROR_STOP=1 -U "$database_user" -d "$database_name"
exit 1 if [ $? -ne 0 ]; then
echo "ERROR: Failed to recover PostgreSQL dump"
exit 1
fi
exit 0
fi
elif [ "$database_type" = "mariadb" ]; then
if [ -n "$database_container" ] && [ -n "$database_password" ] && [ -n "$database_name" ]; then
echo "recover mysql dump"
cat "$backup_sql" | docker exec -i "$database_container" mariadb -u "$database_user" --password="$database_password" "$database_name"
if [ $? -ne 0 ]; then
echo "ERROR: Failed to recover mysql dump"
exit 1
fi
exit 0
fi fi
exit 0
fi fi
echo "A database backup exists, but a parameter is missing." echo "A database backup exists, but a parameter is missing."
exit 1 exit 1
fi fi
# FILE RECOVERY # FILE RECOVERY