From d2b699c2716c79af8874a9b3def3fe84b03d2793 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Fri, 12 Jan 2024 11:47:46 +0100 Subject: [PATCH] Implemented postgres recovery --- recover-docker-from-local.sh | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/recover-docker-from-local.sh b/recover-docker-from-local.sh index a6e8de1..5a4d3d8 100644 --- a/recover-docker-from-local.sh +++ b/recover-docker-from-local.sh @@ -25,18 +25,31 @@ backup_sql="/$backup_folder/sql/$database_name.backup.sql" # DATABASE RECOVERY if [ -f "$backup_sql" ]; 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 + if [ "$database_type" = "postgres" ]; then + if [ -n "$database_container" ] && [ -n "$database_password" ] && [ -n "$database_name" ]; then + echo "Recover PostgreSQL dump" + export PGPASSWORD="$database_password" + cat "$backup_sql" | docker exec -i "$database_container" psql -U "$database_user" -d "$database_name" + 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 - exit 0 fi echo "A database backup exists, but a parameter is missing." exit 1 -fi +fi # FILE RECOVERY