-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrestore.sh
More file actions
56 lines (44 loc) · 1.2 KB
/
restore.sh
File metadata and controls
56 lines (44 loc) · 1.2 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
# Exit on error
set -e
# Check if backup file is provided
if [ -z "$1" ]; then
echo "Usage: $0 <backup_file>"
echo "Example: $0 ./backups/trippz_backup_20250426_123456.sql.gz"
exit 1
fi
BACKUP_FILE=$1
# Check if backup file exists
if [ ! -f "$BACKUP_FILE" ]; then
echo "Error: Backup file not found: $BACKUP_FILE"
exit 1
fi
# Load environment variables
if [ -f .env ]; then
export $(cat .env | grep -v '^#' | xargs)
else
echo "Error: .env file not found"
exit 1
fi
# Decompress backup if it's compressed
if [[ "$BACKUP_FILE" == *.gz ]]; then
echo "Decompressing backup file..."
gunzip -c "$BACKUP_FILE" > "${BACKUP_FILE%.gz}"
BACKUP_FILE="${BACKUP_FILE%.gz}"
fi
# Stop the application
echo "Stopping the application..."
docker-compose down
# Start only the database
echo "Starting the database..."
docker-compose up -d postgres
# Wait for the database to be ready
echo "Waiting for the database to be ready..."
sleep 10
# Restore the database
echo "Restoring the database..."
cat "$BACKUP_FILE" | docker-compose exec -T postgres psql -U $POSTGRES_USER $POSTGRES_DB
# Start the application
echo "Starting the application..."
docker-compose up -d
echo "Restore completed successfully!"