-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0b03960
commit 95af164
Showing
14 changed files
with
566 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -108,27 +108,24 @@ psql -h 127.0.0.1 -p 15432 -U postgres | |
|
||
We have integrated a setup tool in the Docker image that helps replicate data from your primary (MySQL|Postgres) server to MyDuck Server. The tool is available via the `SETUP_MODE` environment variable. In `REPLICA` mode, the container will start MyDuck Server, dump a snapshot of your primary (MySQL|Postgres) server, and start replicating data in real-time. | ||
|
||
#### MySQL Replica Setup | ||
|
||
```bash | ||
docker run \ | ||
--network=host \ | ||
-p 13306:3306 \ | ||
-p 15432:5432 \ | ||
--privileged \ | ||
--workdir=/home/admin \ | ||
--env=SETUP_MODE=REPLICA \ | ||
--env=MYSQL_HOST=<mysql_host> \ | ||
--env=MYSQL_PORT=<mysql_port> \ | ||
--env=MYSQL_USER=<mysql_user> \ | ||
--env=MYSQL_PASSWORD=<mysql_password> \ | ||
--env=SOURCE_DSN="<postgresql|mysql>://<user>:<password>@<host>:<port>/<dbname>" | ||
--detach=true \ | ||
apecloud/myduckserver:latest | ||
``` | ||
`SOURCE_DSN` specifies the connection string to the primary database server, which can be either MySQL or PostgreSQL. | ||
|
||
#### PostgreSQL Replica Setup | ||
- **MySQL Primary:** Use the MySQL URI scheme, e.g., | ||
`--env=SOURCE_DSN=mysql://root:[email protected]:3306` | ||
|
||
```bash | ||
TODO | ||
``` | ||
- **PostgreSQL Primary:** Use the PostgreSQL URI scheme, e.g., | ||
`--env=SOURCE_DSN=postgres://postgres:[email protected]:5432` | ||
|
||
### Connecting to Cloud MySQL & Postgres | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#!/bin/bash | ||
|
||
usage() { | ||
echo "Usage: $0 --postgres_host <host> --postgres_port <port> --postgres_user <user> --postgres_password <password> [--myduck_host <host>] [--myduck_port <port>] [--myduck_user <user>] [--myduck_password <password>] [--myduck_in_docker <true|false>]" | ||
exit 1 | ||
} | ||
|
||
MYDUCK_HOST=${MYDUCK_HOST:-127.0.0.1} | ||
MYDUCK_PORT=${MYDUCK_PORT:-5432} | ||
MYDUCK_USER=${MYDUCK_USER:-mysql} | ||
MYDUCK_PASSWORD=${MYDUCK_PASSWORD:-} | ||
MYDUCK_SERVER_ID=${MYDUCK_SERVER_ID:-2} | ||
MYDUCK_IN_DOCKER=${MYDUCK_IN_DOCKER:-false} | ||
|
||
while [[ $# -gt 0 ]]; do | ||
case $1 in | ||
--postgres_host) | ||
SOURCE_HOST="$2" | ||
shift 2 | ||
;; | ||
--postgres_port) | ||
SOURCE_PORT="$2" | ||
shift 2 | ||
;; | ||
--postgres_user) | ||
SOURCE_USER="$2" | ||
shift 2 | ||
;; | ||
--postgres_password) | ||
SOURCE_PASSWORD="$2" | ||
shift 2 | ||
;; | ||
--myduck_host) | ||
MYDUCK_HOST="$2" | ||
shift 2 | ||
;; | ||
--myduck_port) | ||
MYDUCK_PORT="$2" | ||
shift 2 | ||
;; | ||
--myduck_user) | ||
MYDUCK_USER="$2" | ||
shift 2 | ||
;; | ||
--myduck_password) | ||
MYDUCK_PASSWORD="$2" | ||
shift 2 | ||
;; | ||
--myduck_server_id) | ||
MYDUCK_SERVER_ID="$2" | ||
shift 2 | ||
;; | ||
--myduck_in_docker) | ||
MYDUCK_IN_DOCKER="$2" | ||
shift 2 | ||
;; | ||
*) | ||
echo "Unknown parameter: $1" | ||
usage | ||
;; | ||
esac | ||
done | ||
|
||
# Check if all parameters are set | ||
if [[ -z "$SOURCE_HOST" || -z "$SOURCE_PORT" || -z "$SOURCE_USER" ]]; then | ||
echo "Error: Missing required Postgres connection variables: SOURCE_HOST, SOURCE_PORT, SOURCE_USER." | ||
usage | ||
fi | ||
|
||
# Step 1: Check Postgres configuration | ||
echo "Checking Postgres configuration..." | ||
# TODO(neo.zty): add check for Postgres configuration | ||
|
||
# Step 2: Establish replication | ||
echo "Starting replication..." | ||
export PUBLICATION_NAME="myduck_publication" | ||
export SUBSCRIPTION_NAME="myduck_subscription" | ||
|
||
CREATE_SUBSCRIPTION_SQL="CREATE SUBSCRIPTION ${SUBSCRIPTION_NAME} \ | ||
CONNECTION 'dbname=${SOURCE_DATABASE} host=${SOURCE_HOST} port=${SOURCE_PORT} user=${SOURCE_USER} password=${SOURCE_PASSWORD}' \ | ||
PUBLICATION ${PUBLICATION_NAME};" | ||
|
||
psql -h $MYDUCK_HOST -p $MYDUCK_PORT -U $MYDUCK_USER <<EOF | ||
${CREATE_SUBSCRIPTION_SQL} | ||
EOF | ||
|
||
if [[ -n "$?" ]]; then | ||
echo "SQL executed successfully." | ||
else | ||
echo "SQL execution failed. Check the error message above." | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.