I want to use Amazon Simple Storage Service (Amazon S3) to migrate data from my self-managed MySQL database to an Amazon Aurora MySQL-Compatible Edition DB cluster.
Resolution
Install Percona Xtrabackup
To directly copy your MySQL data directory and its files, use the Percona XtraBackup tool. It's a best practice to use this tool for databases larger than 100 gigabytes (GB) for a faster restoration time. For more information about the tool, see About Percona XtraBackup on the Percona XtraBackup website.
Note: You can't use the Restore from S3 option to restore snapshots that you exported to Amazon S3.
For MySQL 5.7 migrations, use Installing Percona XtraBackup 2.4 on the Percona XtraBackup website. For MySQL 8.0 migrations, use Install Percona XtraBackup 8.0 overview on the Percona XtraBackup website. Make sure that the Percona XtraBackup version is compatible with the engine version of your source database.
Back up your data
Complete the following steps:
-
Connect to your Amazon Elastic Compute Cloud (Amazon EC2) instance or on-premises server that runs the MySQL database.
-
To back up the database, run the following command:
xtrabackup --backup --user=myuser --password --stream=xbstream \--target-dir=/on-premises/s3-restore/backup | split -d --bytes=500MB \
- /on-premises/s3-restore/backup/backup.xbstream
Note: Replace myuser with your source database username and /on-premises/s3-restore/backup with the directory where you want to create the output file. This command creates a backup of your MySQL database that's split into multiple xbstream files.
Aurora doesn't restore everything from your source. You must manually recreate the following resources:
- User AWS accounts
- Functions
- Stored procedures
- Time zone information
Upload your backup to an S3 bucket
Complete the following steps:
- Create an S3 bucket.
Note: Your bucket must be in the same AWS Region as your EC2 instance and your Aurora DB cluster.
- Select your new bucket, and then choose Create folder.
- Select the new folder, and then choose Upload.
- Upload the files that the Percona XtraBackup tool created.
(Optional) Configure additional properties such as permissions or properties based on your use case.
- Choose Upload.
Note: When you upload a file to an S3 bucket, you can use server-side encryption to encrypt the data.
Import your database from Amazon S3 to Aurora
Complete the following steps:
- Open the Amazon Relational Database Service (Amazon RDS) console.
- In the navigation pane, choose Dashboard .
- Choose Restore Aurora DB cluster from S3.
- For Source engine version, enter your source MySQL engine version. You can also enter a later engine version.
- From the S3 backup location dropdown list, select the S3 bucket that you created.
- For S3 bucket prefix, enter your bucket name.
Important: Don't use leading or trailing slashes (/) when you enter the bucket name.
- Create an AWS Identity and Access Management (IAM) role to allow Amazon RDS to access the S3 bucket, and then choose Next step.
- Configure your DB instance details, and then choose Next step.
- Configure your Advanced settings and Database options. For DB cluster identifier, enter your IAM role.
- Choose Launch DB instance.
- Wait until the cluster is in the Available state. Then, to verify that you created your Aurora DB instance, choose View your DB instances.
Related information
The backup cycle - full backups on the Percona XtraBackup website
Migrating data from an external MySQL database to an Amazon Aurora MySQL DB cluster
Physical migration from MySQL by using Percona XtraBackup and Amazon S3