This guide assumes you are working on a dedicated migration workstation,
a machine with access to both the source and destination environments,
used for managing the migration.
Save the manage_source_registry_db.sh script to your local machine.
This script copies the Enzi and MSR databases and starts local instances.
Click for the script
#!/bin/bashset-euopipefail
SCRIPT_VERSION="1.0.1"# Default portsENZI_RETHINKDB_PORT=28015ENZI_CLUSTER_PORT=29015MSR_RETHINKDB_PORT=28016MSR_CLUSTER_PORT=29016SCRIPT_NAME=$(basename"$0")
check_client_bundle_sourced(){if[[-z"${DOCKER_HOST:-}"]]||[[-z"${DOCKER_TLS_VERIFY:-}"]]||[[-z"${DOCKER_CERT_PATH:-}"]];thenechoecho"WARNING: Docker client environment variables not detected."echo"It is recommended to source the MKE admin client bundle (e.g., 'source env.sh')"echo"to ensure access to the source registry cluster."echofi}
show_help(){echoecho"Overview:"echo" Use this script to copy and expose the source registry databases (MKE auth"echo" store and MSR DB store) to the MSR 4 migration tool."echoecho"Prerequisites:"echo" All prerequisites apply to the system where this script is executed."echo" - Docker (or MCR) installed and running (see https://docs.docker.com/get-docker)."echo" - RethinkDB installed (see https://rethinkdb.com/docs/install)."echo" - MKE admin client bundle applied to access the source registry cluster (see"echo" https://docs.mirantis.com/mke/3.8/ops/access-cluster/client-bundle/download-client-bundle.html)."echoecho"Usage:"echo" $SCRIPT_NAME [options]"echoecho"Options:"echo" -c, --copy Copy both eNZi and MSR databases (requires Docker)"echo" --copy-enzidb Copy only the eNZi DB (requires Docker)"echo" --copy-msrdb Copy only the MSR DB (requires Docker)"echo" -e, --start-enzidb Start eNZi DB (requires RethinkDB)"echo" -m, --start-msrdb Start MSR DB (requires RethinkDB)"echo" --enzi-driver PORT Override eNZi driver port (default: 28015)"echo" --enzi-cluster PORT Override eNZi cluster port (default: 29015)"echo" --msr-driver PORT Override MSR driver port (default: 28016)"echo" --msr-cluster PORT Override MSR cluster port (default: 29016)"echo" -v, --version Show script version"echo" -h, --help Show this help message"echoecho"Notes:"echo" The --start-enzidb and --start-msrdb options run RethinkDB in the foreground (i.e. blocking)."echo" The script will not return until the database process exits."echo" Do not use both options in the same invocation (use a separate terminal for each)."echoecho"Examples:"echo" $ # Copy and start the MKE auth store (eNZi) DB"echo" $ ./$SCRIPT_NAME --copy-enzidb --start-enzidb"echoecho" $ # Copy and start the MSR DB"echo" $ ./$SCRIPT_NAME --copy-msrdb --start-msrdb"echoexit0}
error_missing_binary(){echo"Error: Required binary '$1' is not installed or not in PATH.">&2exit1}
check_docker(){if!command-vdocker>/dev/null2>&1;thenerror_missing_binary"docker"fi}
check_rethinkdb(){if!command-vrethinkdb>/dev/null2>&1;thenerror_missing_binary"rethinkdb"fi}
copyEnziDb(){check_docker
mkdir-pdb_data
echo"Copying eNZi DB from Swarm leader..."# Step 1: Get Swarm leader hostnamelocalLEADER_HOSTNAME
LEADER_HOSTNAME=$(dockernodels--format'{{.Hostname}}\t{{.ManagerStatus}}'|awk'$2 == "Leader" {print $1}')if[-z"$LEADER_HOSTNAME"];thenecho"ERROR: Could not identify Swarm leader node.">&2exit1fiecho"Swarm leader is: $LEADER_HOSTNAME"# Step 2: Find matching containerlocalCONTAINER
CONTAINER=$(dockerps-a--format'{{.Names}}'|grep"$LEADER_HOSTNAME/ucp-auth-store")if[-z"$CONTAINER"];thenecho"ERROR: Could not find ucp-auth-store container on leader node ($LEADER_HOSTNAME).">&2exit1fiecho"Using container: $CONTAINER"# Step 3: Perform the copy with retrieslocalRETRIES=3localSUCCESS=falseforiin$(seq1$RETRIES);doifdockercp"$CONTAINER:/var/data"db_data/enzi;thenSUCCESS=truebreakfiecho"Retry $i failed. Retrying in 3 seconds..."sleep3doneif!$SUCCESS;thenecho"ERROR: Failed to copy eNZi DB after $RETRIES attempts.">&2exit1fi}
copyMsrDb(){check_docker
mkdir-pdb_data
echo"Copying MSR DB..."REPLICA_ID=$(dockercontainerls--format'{{.Names}}'-fname=dtr-rethink|awk-F'-''{print $NF}'|sort|head-n1)if[[-z"$REPLICA_ID"]];thenecho"Error: Could not determine DTR replica ID.">&2exit1filocalRETRIES=3localSUCCESS=falseforiin$(seq1$RETRIES);doifdockercpdtr-rethinkdb-"$REPLICA_ID":/datadb_data/msr;thenSUCCESS=truebreakfiecho"Retry $i failed. Retrying in 3 seconds..."sleep3doneif!$SUCCESS;thenecho"ERROR: Failed to copy MSR DB after $RETRIES attempts.">&2exit1fi}
startEnziDb(){check_rethinkdb
echo"Starting eNZi DB on driver port $ENZI_RETHINKDB_PORT and cluster port $ENZI_CLUSTER_PORT..."rethinkdb--bindall--no-update-check--no-http-admin\--directory./db_data/enzi/rethinkdb\--driver-port"$ENZI_RETHINKDB_PORT"\--cluster-port"$ENZI_CLUSTER_PORT"}
startMsrDb(){check_rethinkdb
echo"Starting MSR DB on driver port $MSR_RETHINKDB_PORT and cluster port $MSR_CLUSTER_PORT..."rethinkdb--bindall--no-update-check--no-http-admin\--directory./db_data/msr/rethink\--driver-port"$MSR_RETHINKDB_PORT"\--cluster-port"$MSR_CLUSTER_PORT"}# FlagsCOPY_DB=falseCOPY_ENZI=falseCOPY_MSR=falseSTART_ENZI=falseSTART_MSR=false# Parse argumentsTEMP=$(getopt-ocemhv--longcopy,copy-enzidb,copy-msrdb,start-enzidb,start-msrdb,help,version,enzi-driver:,enzi-cluster:,msr-driver:,msr-cluster:-n"$SCRIPT_NAME"--"$@")if[$?!=0];thenshow_help;fievalset--"$TEMP"whiletrue;docase"$1"in-c|--copy)COPY_DB=true;shift;;--copy-enzidb)COPY_ENZI=true;shift;;--copy-msrdb)COPY_MSR=true;shift;;-e|--start-enzidb)START_ENZI=true;shift;;-m|--start-msrdb)START_MSR=true;shift;;--enzi-driver)ENZI_RETHINKDB_PORT="$2";shift2;;--enzi-cluster)ENZI_CLUSTER_PORT="$2";shift2;;--msr-driver)MSR_RETHINKDB_PORT="$2";shift2;;--msr-cluster)MSR_CLUSTER_PORT="$2";shift2;;-v|--version)echo"$SCRIPT_NAME version $SCRIPT_VERSION"exit0;;-h|--help)show_help;;--)shift;break;;*)echo"Unexpected option: $1";show_help;;esacdone# Show help if no actionable options were passedif!$COPY_DB&&!$COPY_ENZI&&!$COPY_MSR&&!$START_ENZI&&!$START_MSR;thenshow_help
fi# Prevent simultaneous start (both are blocking)if$START_ENZI&&$START_MSR;thenechoecho"ERROR: Cannot start both eNZi and MSR DBs in the same script run."echo"These are blocking processes. Please run them in separate terminal sessions."echoexit1fi# Prevent mismatched copy/start combinations unless using --copyif!$COPY_DB;thenif{$COPY_ENZI&&$START_MSR;}||{$COPY_MSR&&$START_ENZI;};thenechoecho"ERROR: Cannot mix eNZi and MSR operations in a single invocation."echo"For example, do not use --copy-msrdb with --start-enzidb."echo"Use consistent options for the same registry component."echoexit1fifi# Warn if copying without client bundleif$COPY_DB||$COPY_ENZI||$COPY_MSR;thencheck_client_bundle_sourced
fi# Perform copyif$COPY_DB||$COPY_ENZI;thencopyEnziDb
fiif$COPY_DB||$COPY_MSR;thencopyMsrDb
fi# Start DBsif$START_ENZI;thenstartEnziDb
fiif$START_MSR;thenstartMsrDb
fi
Start the required local databases:
Note
You need to source a client bundle that has access to the source registry
to use the copy commands.
MSR 2.9
Important
Both commands must be executed, and the processes must remain
active throughout the migration.
Select one of the following options to ensure they stay running:
Open each command in a separate terminal window or tab.
Run each command in the background by appending &.
Enzi database access
To copy and start a local Enzi database instance, run: