Most efficient way to clone an AWS RDS database?

喜你入骨 提交于 2021-02-18 22:44:34

问题


I have 2 MySQL databases running on a server called X and Y, which both have identical content. A series of updates run throughout the day, which changes the content of X. At the end of the day, a process runs that compares the content of X with the content of Y (for various tables) in order to discover new rows, updated row data etc. Once the updates have been processed, mysqldump is used to dump X and then Y is overwritten with the dump. Both X and Y are now the same again, and the whole process repeats.

I'm investigating migration of these databases to Amazon RDS. What's the most efficient way to accomplish the process outlined above?

I understand that I can take a snapshot of a DB and restore it, but I think this is at the instance level only? That would mean I have to run 2 instances, which seems unnecessary. I don't have a problem running both databases on the same instance (I don't want to pay for more than one instance unnecessarily).

Do I just do what I'm doing now i.e. mysqldump X and restore it to Y, or is there some other method/shortcut that RDS provides?


回答1:


Consider migrating to RDS Aurora for MySQL.

It supports native copy-on-write clones of the entire database (meaning server instance, not schema) without the need to make an actual "copy."

Copy-on-write means the "original" server and the "clone" share the same physical disk (called an Aurora Cluster Volume, which is replicates itself twice across 3 availability zones, using a 4/6 quorum), with both servers sharing the same disk blocks until one of them makes a change... which is when the copy action actually occurs ("on write"). So, you only use as much storage as is required to store your original working data set plus changes that occurred after cloning.

No server is the master in such a setup -- they all operate independently after cloning. I suspect that I'm not doing this innovation justice with my description -- it involves quite a bit of dark magic. See the write-up (with illustrations of copy-on-write): http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Aurora.Managing.Clone.html

Aurora is compatible with MySQL 5.6. To be more precise, Aurora is MySQL 5.6, with MyISAM removed and InnoDB heavily rewritten to optimize performance and work with the replicated Aurora Cluster Volume storage technology.




回答2:


Since the title is concerned AWS instance migration the best way is with my case (can be vary to others case)

  1. Goto -> https://console.aws.amazon.com/rds
  2. Select your DB Instance
  3. Actions -> Take Snapshot
  4. Goto -> https://console.aws.amazon.com/rds
  5. Snapshots from left pane
  6. select your snapshot just created
  7. Action -> Restore Snapshot

After above steps you will be redirected to RDS instance creation page fill out required fields as per requirements and you are done with migration :D




回答3:


You could setup AWS MySQL RDS instance as a slave of an external master.

After loading a full dump to RDS, Call the stored procedure mysql.rds_set_external_master like this:

mysql> call mysql.rds_set_external_master ('10.10.3.2', 3306, 'replica', 'password', 'mysql-bin-changelog.122', 108433, 0);

Then start the replication by doing:

mysql> call mysql.rds_start_replication;

Once you have data in sync you can promote RDS to master by doing:

mysql> call mysql.rds_stop_replication;
mysql> call mysql.rds_reset_external_master;

By doing this either using your external X or Y servers, the AWS RDS behaves like a replica, the one you could use as your future master if required.




回答4:


A bit late in the day but I have just managed to do this by (1) creating a database back up to S3 and then (2) restoring the backup from S3, i.e.

a. Create database back up in S3

EXEC msdb.dbo.rds_backup_database @source_db_name = '<database-name-goes-here>'
                                 ,@s3_arn_to_backup_to = 'arn:aws:s3:::<bucket-name-goes-here>/<backup-filename-goes-here>.bak'
                                 ,@overwrite_S3_backup_file = 1;

b. Wait for the task to complete. You can execute the following SQL to check this

exec msdb.dbo.rds_task_status @db_name='<database-name-goes-here>';

c. When the lifecycle is "SUCCCESS" you can then restore from the S3 bucket using the following command

exec msdb.dbo.rds_restore_database @restore_db_name='<new-database-name-goes-here>'
                                  ,@s3_arn_to_restore_from='arn:aws:s3:::<bucket-name-goes-here>/<backup-filename-goes-here>.bak';

d. Again you can monitor the status of the restore with the following SQL command

exec msdb.dbo.rds_task_status @db_name='<database-name-goes-here>';


来源:https://stackoverflow.com/questions/46815777/most-efficient-way-to-clone-an-aws-rds-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!