This topic tells you how to migrate a GCP Relational Database Service (Google Cloud SQL) for MySQL instance from the GCP Service Broker for VMware Tanzu tile to the Tanzu Cloud Service Broker for GCP tile.
About Migrating Data to Google Cloud SQL for MySQL Instance
Because the GCP Service Broker for VMware Tanzu (hereafter referred to as the legacy broker) tile is going out of support, you need to move from MySQL instances that were created by the legacy broker over to Cloud Service Broker for GCP.
The Cloud Service Broker for GCP plans are configurable. When migrating, examine the configuration of the plans in use with the legacy broker and create matching plans in Cloud Service Broker for GCP.
You can use the GCP Database Import and Export tool to migrate data between Google Cloud SQL for MySQL instances. The tool copies data from one database to a GCP bucket and from there to another database instance. Because the original database is not modified, you can revert the migration if you detect any problems.
Matching Configuration
Both the legacy broker and Cloud Service Broker for GCP allow you to customize service plans.
You must create plans in Cloud Service Broker for GCP that match the plans used in the legacy broker. New service instances must be created with the same major version of MySQL as the old instances, and with the same available disk size or larger.
You might find it useful to create a test service instance and compare the properties in the GCP console. For how to configure plans, see Configure Services with Cloud Service Broker for GCP.
Migrating Data
You might want to migrate data from instances created with the legacy broker to instances created with Cloud Service Broker for GCP.
Migration of data might incur app downtime. The amount of downtime depends on the method chosen.
There are many options for performing data migration, which include GCP SQL Import and Export, manual data migration, and options available from other vendors. For more information about the data migration process, see the documentation for the option that you choose.
In general, the data migration steps are:
- Create a Google Cloud SQL for MySQL instance using Cloud Service Broker for GCP.
- Create a backup of the MySQL instance managed by the legacy broker.
- Restore a backup of the data from a legacy broker MySQL instance in the newly created instance.
- Unbind apps from the legacy broker MySQL instance and bind them to the newly created instance.
- Delete the legacy instance after the migration is finished.
Migrate Data from a GCP Service Broker for VMware Tanzu MySQL Instance
Because the GCP SQL Import and Export tool does not support a streaming or continuous replication, consider putting your application in read-only mode while migrating.
To migrate data from an existing legacy MySQL instance to Cloud Service Broker for GCP:
-
Create a bucket to hold the backup files by running:
gsutil mb gs://BACKUP-BUCKET-NAME
Where
BACKUP-BUCKET-NAME
is a name you choose. It must be lowercase. -
Get the
VCAP_SERVICES
JSON for the legacy MySQL instance by running:cf env APP-NAME
Where
APP-NAME
is the name of an app that is bound to a service instance from the legacy broker. -
From the
VCAP_SERVICES
JSON, record the values ofdatabase_name
, which is yourOLD-INSTANCE-DB-NAME
, andinstance_name
, which is yourOLD-INSTANCE-ID
. -
Create a new MySQL service instance using Cloud Service Broker for GCP by running:
cf create-service csb-google-mysql PLAN-NAME NEW-SERVICE-INSTANCE-NAME -b \ cloud-service-broker-gcp -c '{"db_name":"OLD-INSTANCE-DB-NAME", \ "mysql_version": "OLD-INSTANCE-MYSQL-VERSION" }'
Where:
PLAN-NAME
is the name of the Cloud Service Broker for GCP plan you want to use for the new instance. Ensure this plan matches the plan used in the legacy broker.NEW-SERVICE-INSTANCE-NAME
is the name you want for your new MySQL service instance.OLD-INSTANCE-DB-NAME
is thedatabase_name
you recorded in the previous step.OLD-INSTANCE-MYSQL-VERSION
is the same MySQL version as your old service instance.
-
Retrieve the GCP database instance ID for the new service instance. The GCP database instance ID is the Cloud Foundry service instance GUID with the prefix
csb-mysql-
added to it. This is a string similar tocsb-mysql-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
.Get the Cloud Foundry service instance GUID by running:
cf service NEW-SERVICE-INSTANCE-NAME --guid
-
Create a backup of the old service instance with GCP Import and Export by running:
# Give the old database instance service account access to the newly created bucket. INSTANCE_SERVICE_ACCOUNT_NAME=$(gcloud sql instances describe OLD-INSTANCE-ID \ --format json | jq -r .serviceAccountEmailAddress) gsutil acl ch -u "${INSTANCE_SERVICE_ACCOUNT_NAME}:W" gs://BACKUP-BUCKET-NAME # Run the export gcloud sql export sql OLD-INSTANCE-ID "gs://BACKUP-BUCKET-NAME/backup.sql" -d OLD-INSTANCE-DB-NAME
Where:
OLD-INSTANCE-ID
is theinstance_name
you recorded in an earlier step.BACKUP-BUCKET-NAME
is the name of the bucket to hold the backup files you created in an earlier step.OLD-INSTANCE-DB-NAME
is thedatabase_name
you recorded in an earlier step.
-
(Optional) Verify the contents of the export by inspecting the contents of the created SQL dump file. To do so, use
gsutil
to download it by running:gsutil cp "gs://BACKUP-BUCKET-NAME/backup.sql" PATH-TO-SQL-DUMP-FILE
Where
PATH-TO-SQL-DUMP-FILE
is the filepath where you want to download the local copy of the dump file.You can inspect the dump file with a text editor of your choice.
-
Restore the backup of the old service instance into the new service instance. See the following example:
# Give the new database instance service account access to the newly created bucket. INSTANCE_SERVICE_ACCOUNT_NAME=$(gcloud sql instances describe NEW-INSTANCE-ID \ --format json | jq -r .serviceAccountEmailAddress) gsutil acl ch -u "${INSTANCE_SERVICE_ACCOUNT_NAME}:R" 'gs://BACKUP-BUCKET-NAME/*' # Run the import gcloud sql import sql NEW-INSTANCE-ID "gs://BACKUP-BUCKET-NAME/backup.sql" -d OLD-INSTANCE-DB-NAME
Where:
NEW-INSTANCE-ID
is the GCP database instance ID for the new service instance you retrieved in an earlier step.BACKUP-BUCKET-NAME
is the name of the bucket to hold the backup files you created in an earlier step.OLD-INSTANCE-DB-NAME
is thedatabase_name
you recorded in an earlier step.
-
Disconnect the app from the legacy service binding by running:
cf unbind-service APP-NAME LEGACY-SERVICE-INSTANCE-NAME
Where:
APP-NAME
is an app using the legacy MySQL instance.LEGACY-SERVICE-INSTANCE-NAME
is the name of the MySQL instance managed by the legacy broker.
For example:
$ cf unbind-service my-app my-old-instance
-
Bind the app to the new service instance by running:
cf bind-service APP-NAME NEW-SERVICE-INSTANCE
Where:
APP-NAME
is an app that you unbound in the previous step.NEW-SERVICE-INSTANCE
is the name of the Cloud Service Broker for GCP service instance created in an earlier step.
For example:
$ cf bind-service my-app my-csb-gcp-instance
Because Cloud Service Broker for GCP creates new credentials at bind time, this creates new binding credentials for the app.
-
Restage the app by running:
cf restage APP-NAME
-
After the migration has finished, delete the legacy service instance.
Content feedback and comments