76 lines
1.8 KiB
Bash
Executable File
76 lines
1.8 KiB
Bash
Executable File
#!/bin/sh
|
|
set -e
|
|
|
|
echo "Waiting for DM master to be ready..."
|
|
sleep 5
|
|
|
|
# Check if it's TiDB Cloud (requires TLS)
|
|
if echo "$TEST_DB_HOST" | grep -q "tidbcloud.com"; then
|
|
echo "Detected TiDB Cloud - downloading CA certificate for TLS..."
|
|
wget -q -O /tmp/isrgrootx1.pem https://letsencrypt.org/certs/isrgrootx1.pem
|
|
|
|
# Generate source.yaml with TLS for TiDB Cloud
|
|
cat > /tmp/source.yaml <<EOF
|
|
source-id: "test-tidb"
|
|
enable-gtid: false
|
|
enable-relay: false
|
|
server-id: 101
|
|
from:
|
|
host: "$TEST_DB_HOST"
|
|
port: $TEST_DB_PORT
|
|
user: "$TEST_DB_USER"
|
|
password: "$TEST_DB_PASSWORD"
|
|
security:
|
|
ssl-ca: "/tmp/isrgrootx1.pem"
|
|
EOF
|
|
else
|
|
# Generate source.yaml without TLS for regular TiDB
|
|
cat > /tmp/source.yaml <<EOF
|
|
source-id: "test-tidb"
|
|
enable-gtid: false
|
|
enable-relay: false
|
|
from:
|
|
host: "$TEST_DB_HOST"
|
|
port: $TEST_DB_PORT
|
|
user: "$TEST_DB_USER"
|
|
password: "$TEST_DB_PASSWORD"
|
|
EOF
|
|
fi
|
|
|
|
echo "Creating DM source configuration..."
|
|
/dmctl --master-addr=dm-master:8261 operate-source create /tmp/source.yaml || true
|
|
|
|
# Generate task.yaml with multiple tables
|
|
echo "name: \"test-to-local\"
|
|
task-mode: \"all\"
|
|
target-database:
|
|
host: \"tidb\"
|
|
port: 4000
|
|
user: \"root\"
|
|
password: \"\"
|
|
|
|
mysql-instances:
|
|
- source-id: \"test-tidb\"
|
|
block-allow-list: \"sync-tables\"
|
|
|
|
block-allow-list:
|
|
sync-tables:
|
|
do-dbs: [\"$DATABASE_NAME\"]
|
|
do-tables:" > /tmp/task.yaml
|
|
|
|
# Add each table from TABLES variable
|
|
IFS=',' read -ra TABLE_ARRAY <<< "$TABLES"
|
|
for table in "${TABLE_ARRAY[@]}"; do
|
|
table=$(echo "$table" | xargs) # trim whitespace
|
|
echo " - db-name: \"$DATABASE_NAME\"
|
|
tbl-name: \"$table\"" >> /tmp/task.yaml
|
|
done
|
|
|
|
echo "Starting DM sync task..."
|
|
/dmctl --master-addr=dm-master:8261 start-task /tmp/task.yaml || true
|
|
|
|
echo "Checking task status..."
|
|
/dmctl --master-addr=dm-master:8261 query-status test-to-local
|
|
|
|
echo "DM initialization complete!"
|