#!/bin/sh set -e echo "Waiting for DM master to be ready..." sleep 5 # Substitute environment variables in source.yaml cat /configs/source.yaml | \ sed "s/\${TEST_DB_HOST}/$TEST_DB_HOST/g" | \ sed "s/\${TEST_DB_PORT}/$TEST_DB_PORT/g" | \ sed "s/\${TEST_DB_USER}/$TEST_DB_USER/g" | \ sed "s/\${TEST_DB_PASSWORD}/$TEST_DB_PASSWORD/g" \ > /tmp/source.yaml 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!"