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,14 +25,27 @@ backup_sql="/$backup_folder/sql/$database_name.backup.sql"
# DATABASE RECOVERY # DATABASE RECOVERY
if [ -f "$backup_sql" ]; then if [ -f "$backup_sql" ]; 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 -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