|
#!/bin/bash |
|
|
|
|
|
if [ "$DB_IMPORT" = "yes" ]; then |
|
echo "Starting database import..." |
|
|
|
|
|
DUMP_URL=${DUMP_URL:-""} |
|
DUMP_PASSWORD=${DUMP_PASSWORD:-""} |
|
|
|
|
|
if [ -z "$DUMP_URL" ]; then |
|
echo "DUMP_URL is not set. Skipping database import." |
|
|
|
exit 0 |
|
fi |
|
|
|
|
|
echo "Downloading dump file from $DUMP_URL..." |
|
wget -O /tmp/dump.sql "$DUMP_URL" || { echo "Failed to download dump file."; exit 1; } |
|
|
|
|
|
if [ -n "$DUMP_PASSWORD" ]; then |
|
echo "Dump file is protected with a password." |
|
|
|
|
|
PGPASSWORD="$DUMP_PASSWORD" pg_restore -U $DB_POSTGRESDB_USER -d $DB_POSTGRESDB_DATABASE /tmp/dump.sql || { |
|
echo "Failed to import dump file with password."; exit 1; |
|
} |
|
else |
|
echo "Dump file is not password protected." |
|
|
|
|
|
psql -U $DB_POSTGRESDB_USER -d $DB_POSTGRESDB_DATABASE -f /tmp/dump.sql || { |
|
echo "Failed to import dump file."; exit 1; |
|
} |
|
fi |
|
|
|
echo "Database import completed successfully." |
|
else |
|
echo "Skipping database import." |
|
fi |
|
|