Migrate MySQL data to RDS/Aurora Using Xtrabackup

In this blog, I will provide a step by step procedure to migrate from on-premise MySQL to Amazon RDS/Aurora using Percona-xtrabackup

Both RDS and Aurora is a DBAAS provided by Amazon. To know more on DBAAS you can view our presentation here.

When you are having a database in size of few GB, it would be very convenient to take a logical backup using a logical backup tool such as Mysqldump or Mydumper and restore it Amazon RDS/Aurora easily. But this is not the case when you are having a data size of a few hundred GB or TB, Where the logical backup and restore is very painful and time-consuming. To overcome this we can use Xtrabackup ( open source hot backup ), along with S3 to get the required instance in RDS/Aurora

Screen Shot 2018-12-06 at 7.27.50 PM.png

AWS started supporting Xtrabackup restore for Aurora MySQL long time ago and is Supporting RDS from the last few months back, Both follow the same procedure, hence am using RDS for the purpose of restore, since Aurora is on costlier side.

Production Use Case:

Recently I had come across a situation of restoring xtrabackup to Aurora of data size 300GB and it worked like a charm and the data was absolutely fine and also data was restored in 2 hours.

Before going into the demo, first, let us see the limitations in this method

Limitations:

  • Only 5.6 is supported source and destination should be in 5.6
  • Only support for the whole instance (partial backups at database and table is not supported)
  • With RDS the size is limited to 6TB
  • Database objects and user accounts are not migrated properly (will see the workaround here)

The below command to stream the backup directly to S3 bucket, if you are low on local backup space streaming directly avoids the usage of local storage, also make sure to have a strong network pipe.

# xtrabackup --user=root --password='S3cret!123' --backup --stream=tar | gzip -c | s3cmd put - s3://kabileshs3/xtrabackup56.tar.gz

RDS/Aurora also supports the creation of instance from a tar compressed format and also the S3 footprint can be reduced by compressing the backup, Ensure the compressed backup size should not exceed 5TB, this is the max object size supported by S3.

Backup is now uploaded to s3

Creating RDS instance:

Go to RDS console as below

Click “Restore a database instance from Amazon S3”

Select engine to be used with the restored instance, Am using MySQL, You can select Aurora based on your use-case.

Next Specify source backup details ie, S3 and its details

Create a new IAM role for RDS to access the s3 bucket to make the access and restore of the backup

Now the last and the final step proceed to Specify the DB details such as the instance size, engine version as shown in the below screenshot.

Next choose the backup retention, VPC and security group for accessing the DB instance.

Now click next your instance is getting ready

It took around some 20 mins to get instance ready

In the above restore we have just used data, from sysbench so it shouldn’t be an issue, let’s check the data consistency, By checking the count between the source instance and the restored RDS instance as shown below.

 

Data restore on RDS

 

 

Data on the On prem instance

 

Hope you have enjoyed and learned, Also share your much-valued feedback.

Image Courtesy: Photo by Gareth Davies on Unsplash

Advertisement

9 thoughts on “Migrate MySQL data to RDS/Aurora Using Xtrabackup

  1. Have to take all databases. It is possible.
    Example: I have 10 databases in RDS. I need to take all databases in single command using xtrabackup. Please suggest me.

    Like

  2. Xtrabackup will be working in self-managed system​s, not with RDS , for rds you have snapshot option available to take a full backup

    Like

    1. The support is only for 5.6 , you can try the below method
      1, Replace Mariadb binary with Mysql/Percona 5.5
      2, upgrade to 5.6, then use xtrabackup

      Our Support Team can help you with smooth migration

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s