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.

Important

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:

  1. Create a Google Cloud SQL for MySQL instance using Cloud Service Broker for GCP.
  2. Create a backup of the MySQL instance managed by the legacy broker.
  3. Restore a backup of the data from a legacy broker MySQL instance in the newly created instance.
  4. Unbind apps from the legacy broker MySQL instance and bind them to the newly created instance.
  5. Delete the legacy instance after the migration is finished.

Migrate Data from a GCP Service Broker for VMware Tanzu MySQL Instance

Important

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:

  1. 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.

  2. 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.

  3. From the VCAP_SERVICES JSON, record the values of database_name, which is your OLD-INSTANCE-DB-NAME, and instance_name, which is your OLD-INSTANCE-ID.

  4. 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 the database_name you recorded in the previous step.
    • OLD-INSTANCE-MYSQL-VERSION is the same MySQL version as your old service instance.
  5. 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 to csb-mysql-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX.

    Get the Cloud Foundry service instance GUID by running:

    cf service NEW-SERVICE-INSTANCE-NAME --guid
    
  6. 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 the instance_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 the database_name you recorded in an earlier step.
  7. (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.

  8. 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 the database_name you recorded in an earlier step.
  9. 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
    
  10. 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.

  11. Restage the app by running:

    cf restage APP-NAME
    
  12. After the migration has finished, delete the legacy service instance.

check-circle-line exclamation-circle-line close-line
Scroll to top icon