Skip to content

Commit 406239f

Browse files
committed
fix(docker): for the "restore_backup.sh" allow select .env file
1 parent 20c1ff4 commit 406239f

1 file changed

Lines changed: 38 additions & 3 deletions

File tree

scripts/restore_backup.sh

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
88
BACKUPS_DIR="$SCRIPT_DIR/../postgres/backups"
9-
ENV_FILE="$SCRIPT_DIR/../.env"
109

1110
# =============================================================================
1211
# Color output helpers
@@ -70,14 +69,50 @@ print_info "Selected file: $BACKUP_FILENAME"
7069
echo ""
7170

7271
# =============================================================================
73-
# Section 3: Read .env file and extract database configuration
72+
# Section 2.2: Select .env file
7473
# =============================================================================
7574

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+
76103
if [ ! -f "$ENV_FILE" ]; then
77104
print_error "Error: .env file not found at $ENV_FILE. Cannot proceed without database configuration."
78105
exit 1
79106
fi
80107

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+
81116
POSTGRES_HOST="postgres"
82117
POSTGRES_USER="postgres_user"
83118
POSTGRES_PASSWORD="postgres_password"
@@ -185,7 +220,7 @@ fi
185220

186221
# 5.4 Restore from backup
187222
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)
189224
if [ $? -eq 0 ]; then
190225
print_info "Backup successfully restored"
191226
else

0 commit comments

Comments
 (0)