Implemented postgres recovery

This commit is contained in:
Kevin Veen-Birkenbach 2024-01-12 11:47:46 +01:00
parent b7dcb17fd5
commit d2b699c271

View File

@ -25,6 +25,18 @@ backup_sql="/$backup_folder/sql/$database_name.backup.sql"
# DATABASE RECOVERY
if [ -f "$backup_sql" ]; then
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"
@ -34,6 +46,7 @@ if [ -f "$backup_sql" ]; then
fi
exit 0
fi
fi
echo "A database backup exists, but a parameter is missing."
exit 1
fi