Opstree
Published in

Opstree

Database Migration with Zero or minimal downtime

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
  • Strongswan
  • 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.

TL;DR

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.

--

--

--

Opstree is a end-to-end DevOps consultant company which helps different organization to implement DevOps practices

Recommended from Medium

How did Python save our national-recognized school project

Text Blocks (JEP 368)

Ruby and PHP: which is the best fit for your startup?

Applying Laws of Scalability to Technology and People

Running a Rails app with Webpacker and Docker

New listing on BYBIT

How to see logs live in windows

CS371p Spring 2022 Week #14: Sumedh Kandadai

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ankur

Ankur

DevOps Engineer with 10+ years of experience in the IT Industry. In-depth experience in building highly complex, scalable, secure and distributed systems.

More from Medium

AWS Elastic Container Service

API Gateway — Custom Authorizer arn changes not reflecting — Authorizer Error

Can I build my own SAML / OAuth IDP?

Signatures, Key Management, and Trust in Software Supply Chains — Part 2: Exploiting Signatures