In this blog, I will provide a step by step procedure to migrate from on-premise MySQL to Amazon RDS/Aurora using Percona-xtrabackup
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
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
- 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.
Hope you have enjoyed and learned, Also share your much-valued feedback.