Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jul 30, 2025

This PR adds a comprehensive bash script bin/configure-multi-source-replication to set up MySQL multi-source replication with GTID support.

Features

The script automates the complete multi-source replication setup process:

  1. Configuration-driven setup - Uses simple shell environment variables for configuration
  2. Database dumping - Dumps specified databases from each source host using mysqldump with GTID options
  3. Database restoration - Restores dumps to the replica host
  4. Channel configuration - Sets up GTID-based replication channels using CHANGE REPLICATION SOURCE TO ... FOR CHANNEL
  5. Replication startup - Starts replication for all configured channels

Configuration Format

The script uses a simple configuration file format with shell environment variables:

# Source 1
SOURCE1_HOST=db1.example.com
SOURCE1_USER=replication
SOURCE1_PASSWORD=secret123
SOURCE1_DATABASES="database1,database2"

# Source 2
SOURCE2_HOST=db2.example.com
SOURCE2_USER=replication
SOURCE2_PASSWORD=secret456
SOURCE2_DATABASES="database3,analytics_db"

# Optional replica settings
REPLICA_HOST=replica.example.com
REPLICA_USER=root
REPLICA_PASSWORD=replica_secret

Usage

./bin/configure-multi-source-replication /path/to/config.conf

Quality & Standards

  • Follows repository conventions - Uses same patterns as existing setup-mysql-replica script
  • Comprehensive error handling - Graceful failure handling for connection and database issues
  • Detailed logging - Clear timestamped logs for each step of the process
  • MySQL version support - Compatible with both MySQL 5.7 and 8.0+ syntax
  • Minimal dependencies - Only requires standard bash and mysql client tools
  • Linting compliance - Passes all shellcheck and pre-commit hook validations

Implementation Details

The script implements the MySQL multi-source replication workflow as described in the MySQL 8.0 documentation, with proper GTID handling and channel management for production use.

This pull request was created as a result of the following prompt from Copilot chat.

Create a bash script at bin/configure-multi-source-replication to:

  • Accept a configuration file (with environment variable assignments) specifying MySQL source hosts, users, passwords, and databases to replicate.
  • For each source, dump the listed databases using mysqldump from the source host and restore them on the replica.
  • Set up GTID-based multi-source replication channels as described in https://dev.mysql.com/doc/refman/8.0/en/replication-multi-source-configuration.html
  • The script should:
    1. Parse the configuration file (using source or similar to load env variables per source).
    2. For each source, dump the specified databases (ideally as one dump per source, or per database if needed), and restore them to the replica.
    3. Configure the replica to create a replication channel for each source (using CHANGE REPLICATION SOURCE TO ... FOR CHANNEL ... with GTID options).
    4. Start replication for all channels.
    5. Print clear logging for each step and handle errors (fail gracefully if a host/database fails).
  • The configuration file format should be simple (shell env vars) and documented in the script header.
  • The script should require minimal dependencies (standard bash, mysql client tools).

Include clear comments, error handling, and example configuration usage.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Co-authored-by: bdossantos <245284+bdossantos@users.noreply.github.com>
Copilot AI changed the title [WIP] Add bash script to configure multi-source replication for MySQL Add configure-multi-source-replication script for MySQL GTID replication Jul 30, 2025
Copilot AI requested a review from bdossantos July 30, 2025 19:52
Co-authored-by: bdossantos <245284+bdossantos@users.noreply.github.com>
@bdossantos bdossantos force-pushed the copilot/fix-05892e4c-c38f-49e5-bcf9-14880fb4eaef branch from 2410c66 to 6774ba0 Compare August 4, 2025 07:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants