The database is always a critical part of the business and when it's about to migrate it we need to think about various points like integrity and availability.
This blog will help you to migrate the MySQL database from the local data centre to the cloud. We will be going to use the following tool stack
- Percona Xtrabackup
- Object Storage
Percona Xtrabackup is an open-source utility that helps you to take the backup and restore it in an efficient way. Also, you can take incremental backups. It will compress it and will not take any block on the database while creating the backup.
Strongswan is an open-source VPN solution that helps you to connect your DC with the cloud.
First, we need to install the Percona Xtrabackup utility in our database instance. Please make sure you have installed the right version based on the MySQL version. Post-installation we have to take the backup here we will take the incremental backup.
xtrabackup --backup --user=username --password='xxxx' --target-dir=/path/incremental_backup_initial --incremental-basedir=/path/incremental_backup
Now we have the backup. Compress the same and upload it into the bucket. Once the data is available in the bucket we can spin up a database instance in the cloud platform.
After initial setup, we are ready to restore our backup into the new cloud instance. Download the backup from the bucket and install the Percona Xtrabackup there. Prepare the database for restoration
xtrabackup --prepare --apply-log-only --target-dir=mysql_backup --incremental-dir=/path/incremental_mysql_backup
In the incremental process we need to use — apply-log-only option else it will be useless
Now we will restore the same using rsync utility
rsync -avrP /data/backup/ /var/lib/mysql/
Once the backup is restored start the MySQL service. Here maybe you can face some issues while starting the mysql service. In that case please check the permission/ownership or if SELinux is enabled then please check the SELinux context as well.
Now we have done with the initial backup. It's up to you how you wanna go further. You can take some downtime and repeat all the above steps to migrate delta data. Or you can set up an IPsec VPN between the cloud and datacenter and set up master-slave replication once there is no lag you point to the new database endpoints in the application.