mirror of
https://github.com/kevinveenbirkenbach/docker-volume-backup.git
synced 2024-11-22 00:11:03 +01:00
Implemented postgres recovery
This commit is contained in:
parent
b7dcb17fd5
commit
d2b699c271
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user