|
6 | 6 |
|
7 | 7 | SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" |
8 | 8 | BACKUPS_DIR="$SCRIPT_DIR/../postgres/backups" |
9 | | -ENV_FILE="$SCRIPT_DIR/../.env" |
10 | 9 |
|
11 | 10 | # ============================================================================= |
12 | 11 | # Color output helpers |
@@ -70,14 +69,50 @@ print_info "Selected file: $BACKUP_FILENAME" |
70 | 69 | echo "" |
71 | 70 |
|
72 | 71 | # ============================================================================= |
73 | | -# Section 3: Read .env file and extract database configuration |
| 72 | +# Section 2.2: Select .env file |
74 | 73 | # ============================================================================= |
75 | 74 |
|
| 75 | +print_info "Select .env file:" |
| 76 | +echo "" |
| 77 | +echo " 1. Root .env file" |
| 78 | +echo " 2. backend/.env file" |
| 79 | +echo " 3. frontend/.env file" |
| 80 | +echo "" |
| 81 | + |
| 82 | +while true; do |
| 83 | + read -r -p "Enter .env file number (1-3): " env_choice |
| 84 | + |
| 85 | + if ! [[ "$env_choice" =~ ^[0-9]+$ ]]; then |
| 86 | + print_error "Enter a number from 1 to 3" |
| 87 | + continue |
| 88 | + fi |
| 89 | + |
| 90 | + if [ "$env_choice" -lt 1 ] || [ "$env_choice" -gt 3 ]; then |
| 91 | + print_error "Enter a number from 1 to 3" |
| 92 | + continue |
| 93 | + fi |
| 94 | + |
| 95 | + case "$env_choice" in |
| 96 | + 1) ENV_FILE="$SCRIPT_DIR/../.env" ;; |
| 97 | + 2) ENV_FILE="$SCRIPT_DIR/../backend/.env" ;; |
| 98 | + 3) ENV_FILE="$SCRIPT_DIR/../frontend/.env" ;; |
| 99 | + esac |
| 100 | + break |
| 101 | +done |
| 102 | + |
76 | 103 | if [ ! -f "$ENV_FILE" ]; then |
77 | 104 | print_error "Error: .env file not found at $ENV_FILE. Cannot proceed without database configuration." |
78 | 105 | exit 1 |
79 | 106 | fi |
80 | 107 |
|
| 108 | +echo "" |
| 109 | +print_info "Selected .env file: $ENV_FILE" |
| 110 | +echo "" |
| 111 | + |
| 112 | +# ============================================================================= |
| 113 | +# Section 3: Read .env file and extract database configuration |
| 114 | +# ============================================================================= |
| 115 | + |
81 | 116 | POSTGRES_HOST="postgres" |
82 | 117 | POSTGRES_USER="postgres_user" |
83 | 118 | POSTGRES_PASSWORD="postgres_password" |
|
185 | 220 |
|
186 | 221 | # 5.4 Restore from backup |
187 | 222 | print_info "Restoring database \"$POSTGRES_DB\" from file \"$BACKUP_FILENAME\", this may take a few minutes..." |
188 | | -output=$(docker exec -i -e "PGPASSWORD=$POSTGRES_PASSWORD" pneumatic-postgres psql -v ON_ERROR_STOP=1 -U "$POSTGRES_USER" -h "$POSTGRES_HOST" "$POSTGRES_DB" < "$BACKUPS_DIR/$BACKUP_FILENAME" 2>&1) |
| 223 | +output=$(docker exec -i -e "PGPASSWORD=$POSTGRES_PASSWORD" pneumatic-postgres psql -U "$POSTGRES_USER" -h "$POSTGRES_HOST" "$POSTGRES_DB" < "$BACKUPS_DIR/$BACKUP_FILENAME" 2>&1) |
189 | 224 | if [ $? -eq 0 ]; then |
190 | 225 | print_info "Backup successfully restored" |
191 | 226 | else |
|
0 commit comments