How to create "Write" clone of a production RDS Aurora instance? - mysql

I have a production DB that is on RDS Aurora MySQL. I would like to create a "staging" version of it, so I need a complete duplicate/clone of the production version.
Most importantly I need the staging version to have write access to the new instance.
Is this possible?

Review Cloning Databases in an Aurora DB Cluster in the RDS User Guide.
Clones are not the same thing as replicas. A replica, in Aurora, has read-only access to the same data store allowing you to spread out your read workload across multiple instances... but a clone is a readable/writable moment-in-time fork of your original database. Any changes after the clone is created don't change the data on the original database instances (or on any other clones, and up to 15 independent clones are currently supported).
You can also create a new Aurora cluster from a snapshot of your production database, but a clone is probably the preferred solution for two reasons: it's faster to create a clone... but perhaps more importantly, clones use copy-on-write, so until you change the data on either the clone or the master it was cloned from, they share common storage space in the Aurora Cluster Volume that stores the data -- so you're only paying once for storage of the data that never gets changed. How this works is explained, with diagrams, in the RDS User Guide at the link, above.

You can take Backup ( Database snapshot ) on prod and restore the backup into new RDS Aurora servers ( during RDS Aurora instance creation) . It is simple GUI interface in AWS. You can change your permission after database has been restored into stage.

Related

How to sync 2x AWS RDS instances

I have 2x RDS single instances (MySQL) in the same region.
The goal is to copy (A) RDS to (B) RDS on nightly basis.
Is there any way to have this configuration auto sync between 2 RDS instances?
If your goal is to copy the contents of one Amazon RDS database such that another RDS database contains identical content, then it is easiest to use a snapshot:
Create an Amazon RDS Snapshot of the source database
Launch a new Amazon RDS database instance from the Snapshot
Delete the previous Amazon RDS database 'B' database, since it is now out-of-date
The new database launched from the Snapshot will be identical to the source database (except for the instance DNS name).
This operation can be done via AWS CLI commands.
I would suggest looking into DMS ongoing replication as it seems like a potential solution for your use case https://docs.aws.amazon.com/dms/latest/userguide/CHAP_BestPractices.html#CHAP_BestPractices.OnGoingReplication
There are three approaches here.
One is that if you want to "refresh" the database schema on nightly basis, you can use logical backup by using mysqldump/mydumper to export/import the schema and put the script in the scheduler (eg. cron).
The second one you can use is snapshot backup that is provided by AWS, but you need to destroy the previous RDS instances, otherwise you will have many restored RDS from daily snapshot. Ideally, you can create some script that call AWS CLI to remove the previous RDS and restore the snapshot from daily backup. Put the script in the scheduler as well as first option.
A third option is that you can create synchronization using Amazon DMS (Data Migration Service) to migrate the data in a real-time fashion.

AWS RDS MySQL Cross-region replication

I need to create an RDS MySQL instance in us-east-1 and would like to replicate this data in another region (say eu-west-1). I know about read-replicas, and I will be using them also, but I wanted to have a back-up non-read-replica in another region.
Has anyone done this?
Is there code out there that does this replication?
I highly recommend switching from RDS MySQL to RDS Aurora, which is MySQL compatible. You won't have to change anything in your code, the database will still appear to be MySQL to any apps that connect to it. Among the many advantages Aurora has over MySQL is that it supports cross-region replication.
There are several ways to do this. I will cover two easy methods. RDS features are based upon engine (MySQL, Aurora, PostreSQL, etc.). Review as required.
1) Create a read-replica of your existing RDS instance in another region. Then promote that read-replica to master. Now you have a separate instance running in another region. You can then stop this instance to minimize billing (for up to seven days).
2) Create an RDS snapshot. Copy that snapshot to another region. When needed launch a new RDS instance from the snapshot.

Most efficient way to clone an AWS RDS database?

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?
Since the title is concerned AWS instance migration the best way is with my case (can be vary to others case)
Goto -> https://console.aws.amazon.com/rds
Select your DB Instance
Actions -> Take Snapshot
Goto -> https://console.aws.amazon.com/rds
Snapshots from left pane
select your snapshot just created
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
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.
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>';
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.

Daily copy of AWS Aurora database to another AWS Aurora database

We have an AWS Aurora database sitting on an instance that holds all of our production data. I want to be able to perform analytics on that data without doing it in our production environment, so I want to copy the production data on a daily basis to another AWS Aurora database on a completely different instance. Within that "analytics" database, I'll build out all the needed views and stored procedures to aggregate whatever transformed data I need to store.
At first I thought of creating an Aurora replica, but of course that's read-only. I need to find a way to do this outside of the production environment and I feel it's an easy enough task to do, but I just can't find out how to do it. Maybe I haven't been able to ask the write questions, so I came here. How can I achieve this?
This is simple AWS replication.
http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Aurora.Replication.CrossRegion.html
Also if you prefer to use mysql or any other RDBMS use
http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Aurora.Overview.Replication.MySQLReplication.html
It is similar to master slave replication with little difference in sharded data mainted in Aurora.
Replication is the correct (subjective, of course) solution, but you can't use a managed Aurora replica, which is to say you can't use an Aurora replica in the cluster.
That does not, however, mean you can't create your own asynchronous Aurora replica... which would be a second Aurora cluster, an independent master that is writable, but that uses the replication stream (the binary logs, also called "binlogs,") from the master cluster to keep its data in sync.
The one caveat: you must be extremely cautious not to write to any of the tables on the asynchronous cluster that are being replicated from the production master. Do that, of course, and replication breaks. The master cluster will be completely unaffected, but the replica cluster will stop replicating once inconsistent data is detected. But you can create additonal tables, views, and stored programs without issue.
Within an Aurora cluster, there is no need for replication in the traditional sense -- the replicas use the same backing store as the master (the "cluster volume.") Here, we're just replicating from cluster to cluster, identical to the way two ordinary MySQL servers would replicate (in one direction, only, of course).
The setup is essentially identical to the setup for replicating in and out of Aurora, to or from MySQL. Since this solution uses MySQL native replication, the steps are the same.
http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Aurora.Overview.Replication.MySQLReplication.html

Can't create Multi-AZ Aurora RDS Instance

When I restore a MySQL snapshot, I'm given the option to make the new instance Multi-AZ. However for some reason when I restore to Aurora, the "Multi-AZ Deployment" selection is disabled.
I thought possibly this meant it was automatically enabled. However when I go to the running instance details, it specifically lists Multi-AZ: "No".
Is there something I'm missing? Is there some other step I need to do to make Aurora Multi-AZ?
Multi-AZ doesn't mean the same thing in Aurora as it does for MySQL and MariaDB. With Aurora, any replica in the cluster can take over for the master on failure (though the selection is based on priority, so it isn't just a randomly selected replica, if there is more than one replica), and the storage is already/always multi-AZ in Aurora because that's a core part of the Aurora design. So, Aurora can be "converted" to Multi-AZ.
Apparently, that's the only way it is done when creating an Aurora instance from a snapshot, based on this:
You can migrate a DB snapshot of an Amazon RDS MySQL DB instance to create an Aurora DB cluster.
...
You can migrate either a manual or automated DB snapshot. After the DB cluster is created, you can then create optional Aurora Replicas.
http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Aurora.Migrate.RDSMySQL.html
If you create a multi-AZ Aurora cluster without a snapshot, that's all that happens -- a master and a replica are created. In that case, you can actually delete the replica and make it non-multi-AZ, which is a different process than what's involved with MySQL or MariaDB.
"Create a cluster" -- as used in the quote, above -- is a potentially confusing term, since you would naturally assume a cluster means two or more, but in fact an Aurora cluster can technically be a "cluster" of just one instance. Every Aurora instance is part of exactly one cluster. One instance is the primary (master) and any additional instances are replicas.
If the DB cluster doesn't contain any Aurora Replicas, then the primary instance is recreated during a failure event.
http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Aurora.Managing.html#Aurora.Managing.FaultTolerance