-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_dump_with_container.sh
More file actions
executable file
·66 lines (57 loc) · 1.66 KB
/
Copy pathcreate_dump_with_container.sh
File metadata and controls
executable file
·66 lines (57 loc) · 1.66 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
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
# Script to create a pg_dump using a PostgreSQL container
set -e
echo "🚀 Creating pg_dump using PostgreSQL container..."
# Configuration
DB_HOST="omop_postgres" # Container name in the omopmcp_default network
DB_PORT="5432"
DB_NAME="omop"
DB_USER="omop_user"
DB_PASSWORD="omop_password"
DUMP_FILE="omop_dump.sql"
# Check if dump file already exists
if [ -f "$DUMP_FILE.gz" ]; then
echo "⚠️ Found existing dump file: $DUMP_FILE.gz"
read -p "Do you want to overwrite it? (y/N): " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "❌ Aborted."
exit 1
fi
fi
echo "📦 Creating pg_dump using PostgreSQL container..."
# Run pg_dump using a PostgreSQL container
docker run --rm \
--network omopmcp_default \
-e PGPASSWORD="$DB_PASSWORD" \
-v "$(pwd):/backup" \
postgres:15 \
pg_dump \
--host="$DB_HOST" \
--port="$DB_PORT" \
--username="$DB_USER" \
--dbname="$DB_NAME" \
--verbose \
--clean \
--if-exists \
--create \
--no-owner \
--no-privileges \
--schema=omop \
--schema=public \
--file="/backup/$DUMP_FILE"
if [ $? -eq 0 ]; then
echo "✅ pg_dump completed: $DUMP_FILE"
echo "📁 Size: $(du -h "$DUMP_FILE" | cut -f1)"
# Create compressed version
gzip "$DUMP_FILE"
echo "🗜️ Compressed: ${DUMP_FILE}.gz"
echo "📁 Compressed size: $(du -h "${DUMP_FILE}.gz" | cut -f1)"
echo ""
echo "🎉 Dump created successfully!"
echo "📄 File: ${DUMP_FILE}.gz"
echo "💡 You can now use this with Dockerfile.postgres"
else
echo "❌ pg_dump failed!"
exit 1
fi