Is there a way to migrate from first generation cloud sql to second generation with minimal to no downtime?
Dumping my 1st gen DB takes about 30 mintues after I set it to read only (Meaning downtime for me) and I believe import to the 2nd gen will take a long time as well.
What about using a clone while the upgrade is in process and when the upgrade completes copy the difference to the new DB?
I'm using AppEngine, so I was thinking about uploading a new version pointing to the 2nd gen DB while the old version is pointing to the clone. Once the upgrade completes I'll change the version and run a script to copy the missing data.
Could that work? Any better options?
I ended up doing the following:
Here is the script:
#!/bin/sh
DB_IP=127.0.0.1
SQL_FILE_NAME=db-backup.sql
GZ_SQL_FILE_NAME=db-backup.sql.gz
BUCKET_NAME=gs://db-bucket-name
GS_FILE_PTH=$BUCKET_NAME/$GZ_SQL_FILE_NAME
INSTANCE_NAME=1st-gen-instance
NEW_INSTANCE_NAME=2nd-gen-instace
gcloud config set project project-name
gcloud sql instances patch $INSTANCE_NAME --database-flags read_only=on
mysqldump --databases dbname -h $DB_IP -u user --password=password \
--hex-blob --skip-triggers --set-gtid-purged=OFF \
--default-character-set=utf8 > $SQL_FILE_NAME
gzip $SQL_FILE_NAME
gsutil cp -r $GZ_SQL_FILE_NAME $GS_FILE_PTH
SERVICE_ACCOUNT_ADDRESS=$(gcloud sql instances describe $NEW_INSTANCE_NAME | sed -n -e 's/^.*serviceAccountEmailAddress: //p')
gsutil acl ch -u $SERVICE_ACCOUNT_ADDRESS:W $BUCKET_NAME
gsutil acl ch -u $SERVICE_ACCOUNT_ADDRESS:R $GS_FILE_PTH
gcloud sql instances import $NEW_INSTANCE_NAME $GS_FILE_PTH
gsutil acl ch -d $SERVICE_ACCOUNT_ADDRESS:W $BUCKET_NAME
gsutil acl ch -d $SERVICE_ACCOUNT_ADDRESS:R $GS_FILE_PTH