-
-
Notifications
You must be signed in to change notification settings - Fork 145
Expand file tree
/
Copy pathdb_backup.sh
More file actions
executable file
·33 lines (26 loc) · 1 KB
/
db_backup.sh
File metadata and controls
executable file
·33 lines (26 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/bash
echo "Loading environment variables from .env..."
# Check if .env file exists
if [ -f .env ]; then
# Load environment variables from .env file
while IFS='=' read -r key value; do
# Skip empty lines and comments
if [[ ! -z "$key" && ! "$key" =~ ^# ]]; then
# Remove leading/trailing whitespace from key and value
key=$(echo "$key" | xargs)
value=$(echo "$value" | xargs)
export "$key"="$value"
fi
done < .env
else
echo "Error: .env file not found!"
exit 1
fi
echo "Backing up schema for database: $SPARKY_FITNESS_DB_NAME on $SPARKY_FITNESS_DB_HOST:$SPARKY_FITNESS_DB_PORT"
# Set PGPASSWORD for pg_dump
export PGPASSWORD=$SPARKY_FITNESS_DB_PASSWORD
# Execute pg_dump
/opt/homebrew/opt/postgresql@15/bin/pg_dump -U $SPARKY_FITNESS_DB_USER -h $SPARKY_FITNESS_DB_HOST -p $SPARKY_FITNESS_DB_PORT -d $SPARKY_FITNESS_DB_NAME --schema-only --no-owner -f db_schema_backup.sql
# Unset PGPASSWORD for security
unset PGPASSWORD
echo "Backup completed: db_schema_backup.sql"