30 lines
937 B
Bash
30 lines
937 B
Bash
#!/bin/bash
|
|
|
|
DB_HOST="localhost"
|
|
DB_PORT="5432"
|
|
DB_USER="postgres"
|
|
DUMP_BASE_PATH="/opt/pg_dumps"
|
|
|
|
# Список баз
|
|
databases=("edemo_ehd1" "edemo_ehd2" "edemo_ehd3" "edemo_ehd4" "edemo_ehd5"
|
|
"edemo_ehd6" "edemo_ehd7" "edemo_ehd8" "edemo_ehd9" "edemo_ehd10"
|
|
"edemo_ehd11" "edemo_ehd12" "edemo_ehd13" "edemo_ehd14" "edemo_ehd15")
|
|
|
|
# Создаем базы
|
|
for db in "${databases[@]}"; do
|
|
echo "Creating: $db"
|
|
psql -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -c "DROP DATABASE IF EXISTS $db WITH (FORCE)"
|
|
psql -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -c "CREATE DATABASE $db"
|
|
done
|
|
|
|
# Восстанавливаем
|
|
for db in "${databases[@]}"; do
|
|
echo "Restoring: $db"
|
|
if pg_restore -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -d "$db" -F d -j 4 --no-owner "$DUMP_BASE_PATH/${db}.dir"; then
|
|
echo "Restore $db Done"
|
|
else
|
|
echo "Restore $db Failed"
|
|
fi
|
|
done
|
|
|
|
echo "All done" |