Aiven-Open / aiven-mysql-migrate

MySQL® migration tool
Apache License 2.0
10 stars 5 forks source link
database migration mysql

aiven-mysql-migrate

The aim of this tool is to help migrate MySQL servers from one place to another.

aiven-mysql-migrate supports two methods of migration:

Requirements

The tool requires mysql-client package 8.X, which can be installed from https://dev.mysql.com/doc/refman/8.0/en/linux-installation.html

Limitations

Usage

mysql_migrate --help
usage: mysql_migrate [-h] [-d] [-f FILTER_DBS] [--validate-only] [--seconds-behind-master SECONDS_BEHIND_MASTER] [--stop-replication] [--privilege-check-user PRIVILEGE_CHECK_USER] [--force-method FORCE_METHOD]
                     [--dbs-max-total-size DBS_MAX_TOTAL_SIZE] [--output-meta-file OUTPUT_META_FILE] [--allow-source-without-dbs]

MySQL migration tool.

optional arguments:
  -h, --help            show this help message and exit
  -d, --debug           Enable debug logging.
  -f FILTER_DBS, --filter-dbs FILTER_DBS
                        Comma separated list of databases to filter out during migration
  --validate-only       Run migration pre-checks only
  --seconds-behind-master SECONDS_BEHIND_MASTER
                        Max replication lag in seconds to wait for, by default no wait
  --stop-replication    Stop replication, by default replication is left running
  --privilege-check-user PRIVILEGE_CHECK_USER
                        User to be used when replicating for privileges check (e.g. 'checker@%', must have REPLICATION_APPLIER grant)
  --force-method FORCE_METHOD
                        Force the migration method to be used as either replication or dump.
  --dbs-max-total-size DBS_MAX_TOTAL_SIZE
                        Max total size of databases to be migrated, ignored by default
  --output-meta-file OUTPUT_META_FILE
                        Output file which includes metadata such as dump GTIDs (for replication method only) in JSON format.
  --allow-source-without-dbs
                        Allow migrating from a source that has no migratable databases

The following environment variables are used by migration script:

Environment variable are used here instead of usual arguments so that it's not possible to see credentials in the list of long-running processes. As for the mysqldump/mysql subprocesses they won't be visible, because they are hidden by the tools.

The reason for having a separate master URI is a security concern, i.e. for properly managing replication while migrating the super user is needed, which we should not use for importing MySQL dumps, because the SQL statements from the dump will be executed in the context for this user.

Run pre-checks to validate if migration is possible:

SOURCE_SERVICE_URI="mysql://<src_admin>:<pwd>@<src_host>:<port>/?ssl-mode=REQUIRED" \
  TARGET_SERVICE_URI="mysql://<tag_admin>:<pwd>@<tag_host>:<port>/?ssl-mode=REQUIRED" \
  TARGET_MASTER_SERVICE_URI="mysql://<tag_superuser>:<pwd>@<tag_host>:<port>/?ssl-mode=REQUIRED" \
  mysql_migrate --validate-only

ssl-mode parameter can be one of DISABLED or REQUIRED

Migrate:

mysql_migrate --filter-dbs "<temp_db1>,<temp_db2>" --seconds-behind-master 0 --stop-replication

Trademarks

MySQL is a registered trademark of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.