Does AWS RDS support two way replication with local MySQL database? - mysql

I would like to sync the local MySQL database to Amazon RDS MySQL database. I found a solution for EC2 to RDS but not for Local Database to RDS.
I built a database including 12 tables which all I want to get backup them to cloud periodically or automatically.
I do not want to run EC2 server since I need only MySQL database to get backup on cloud.
I need a solution like Microsoft Database Sync Agent. Whenever changes detected in Local Database, it should be synced to the cloud database. How can I make this happen?

You could use the AWS Database Migration Service:
AWS Database Migration Service (AWS DMS) is a cloud service that makes it easy to migrate relational databases, data warehouses, NoSQL databases, and other types of data stores. You can use AWS DMS to migrate your data into the AWS Cloud, between on-premises instances (through an AWS Cloud setup), or between combinations of cloud and on-premises setups.
With AWS DMS, you can perform one-time migrations, and you can replicate ongoing changes to keep sources and targets in sync.

You can achieve this by following below steps.
Make a replica of local server to RDS.
Enable Query logging in local Database
Create a cron job which will process logging queries and it will execute queries on RDS instance in same order.
To generate a replica to RDS you can follow below steps.
You can't replicate your local database to RDS directly. Your need to dump you data and then after you can import it on RDS.
Instead of generating a dump file you can directly import data into RDS using below command.
mysqldump db_name | mysql -h 'other_hostname' db_name
You can find our more about this over here.
https://dev.mysql.com/doc/refman/5.7/en/copying-databases.html
Also first import tables & it's data then after import your triggers, routines & events. If you import together then there is a chances to get conflict and you job will be terminated.

Related

AWS RDS What is the best practice to keep the staging database up to date with production database?

Is there any best practice to keep the staging database up to date with the production database?
For example,
every day at midnight, the production database overwrites the staging database.
If your goal is to make the Staging database an exact copy of the Production database, then you could:
Take a Snapshot of the Production database
Delete the Staging database
Restore a new Staging database from the Snapshot of the Production database
These steps can be automated via a script that calls the AWS Command-Line Interface (CLI). For example, it could use:
aws rds create-db-snapshot
aws rds delete-db-instance
aws rds restore-db-instance-from-db-snapshot
You can achieve the task as said by #John, but there are a few points which we can not know, such as
the status of the clone
notification once complete
Below official Blog will help with everything we need to know during every clone.
Blog: Orchestrating database refreshes for Amazon RDS and Amazon Aurora | AWS Database Blog
CloudFormation Git Repo: aws-samples
/
database-refresh-orchestrator-for-amazon-rds-and-amazon-aurora
[Optional] Migrate from RDS to Aurora
Migrating an RDS for MySQL snapshot to Aurora - Amazon Aurora

How to sync local MySQL database to Amazon RDS database?

I am setting up a connection between MySQL Workbench and Amazon AWS RDS MySQL database. How can I sync the two databases?
The operation (Inserting, deleting and updating) directly happens to cloud (AWS RDS) database instead of storing first on the local database which is further sync to cloud. Because it is taking much time in storing procedure directly to the cloud.
I expect all operations happen first in a local database which then syncs to the cloud database.
You may be interested in using the AWS Database Migration Service, which should be able to meet all of your requirements including remote replication of your local database. (https://aws.amazon.com/dms/)

Replicate Data Regularly from AWS RDS (MySQL) to another Server (EC2 instance)

We have a large AWS RDS(MySQL) Instance and we need to replicate data from it to another Ec2 Instance, daily at a certain time for reporting and analysis purpose.
currently we are using mysqldump to create a dump file and then copy the whole schema which takes a lot of time. Is there a faster way of doing this, it would be a lot better if it copies only the new records.
How can we copy data without copying whole schema every time?
You should look at the Database Migration Service. Don't be confused by the name. It can do continuous or one time replication. From the FAQ:
Q. In addition to one-time data migration, can I use AWS Database
Migration Service for continuous data replication?
Yes, you can use AWS Database Migration Service for both one-time data
migration into RDS and EC2-based databases as well as for continuous
data replication. AWS Database Migration Service will capture changes
on the source database and apply them in a transactionally-consistent
way to the target. Continuous replication can be done from your data
center to the databases in AWS or in the reverse, replicating to a
database in your datacenter from a database in AWS. Ongoing continuous
replication can also be done between homogeneous or heterogeneous
databases. For ongoing replication it would be preferable to use
Multi-AZ for high-availability.
You can use AWS Glue to do the database migration as an ETL job periodically.
You can also consider using AWS Data Migration Service (DMS).
However AWS Glue is preferred over DMS for ETL jobs that runs within AWS and you are familiar with Python or Scala to write the transformation logic.
Q: When should I use AWS Glue vs AWS Database Migration Service?
AWS Database Migration Service (DMS) helps you migrate databases to AWS easily and securely. For use cases which require a database migration from on-premises to AWS or database replication between on-premises sources and sources on AWS, we recommend you use AWS DMS. Once your data is in AWS, you can use AWS Glue to move and transform data from your data source into another database or data warehouse, such as Amazon Redshift.

Is it possible to migrate back from Amazon Aurora to native MySQL in Amazon RDS?

I saw Amazon introduced new Amazon Aurora MySQL migration from native MySQL to Amazon Aurora MySQL.
Would it be possible to migrate back from Amazon Aurora to regular MySQL with Amazon RDS?
Amazon's Aurora is MySQL wire compatible so you can always use tools such as mysqldump to get your data back out into a form that you could use to import back into a regular MySQL instance running in RDS, an EC2 instance or anywhere else for that matter.
Since posting this answer Amazon has also released the Database Migration Service which can be used to do zero downtime migrations between MySQL -> Aurora MySQL (Aurora also now supports PostgreSQL) and back. It also supports heterogeneous migrations such as from Oracle to Aurora MySQL or a number of other sources and targets.
If it's a small database, you can use tools such as Navicat or MySQL Workbench to export the data out. For big databases, you can download aws cli either for Windows or Linux, for Linux it comes with a pre-installed on Amazon Linux AMI. Use aws configure to set up credentials and regions. Use mysqldump from the cli remember the --single-transaction option to avoid locking and take dump preferable from slave replica.
For a subset of the data, you can either use: (Windows example)
mysql> SELECT * FROM database.table
WHERE ......
into OUTFILE '/location/of/path/dumpfile.txt'
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY "\n";
Query OK....
to extract just what you need as flat files which is faster to load into any other MySQL env. You can also setup permission to load into s3 as flat files and export anywhere again if the file is not as big. But for huge data, please use mysqldump.
Percona has a series of steps to follow that outlines how to set up a MySQL replica from an Aurora master. You'd then be able to take it to RDS MySQL from there. In some cases this manual method might make sense.
Overview:
Snap the Aurora instance
Bring up a temp Aurora instance
Dump it (mysqldump)
Create the replica
Migrate traffic
However as #ydaetskcoR suggests, Amazon has the tool and the use case defined for setting up such a replica with DMS. I'd start here is a direct link to that use case.

How Ruby on rails works with Amazon RDS

I have a ruby on rails run on amazon ec2, database is mySQL.
Now I want to use Amazon RDS to backup this database in case the ec2 fails.
I read through the Amazon RDS user guide,it tells how to create a DB instance.
My question is:
1.what is the relation between created DB instance and my ec2 database?
2.When the DB instance "connect" to my ec2, what will happen?
The data used to send to ec2 mySQL server will be send to DB instance?
Is the database totally shifted to DB instance?So before I connect I should creare a same database in DB instance and tell ec2 send data to RDS ever since
3.If not,how the DB instance know the ec2 is down and takeover the data?
EDIT:
(Unsure)Is it that DB instance is just a place to put database.In order to use it,I need to set up database in DB instance,then connect to it by modifying database.yml file(this file tell rails server where the stored data goes).
How Is it possible to tell when the local database stops then at that time switch to DB instance?
There is absolutely no relationship between your EC2 MySQL DB and the RDS DB Instance. So what you are asking for is just not possible.
A better approach I would say is to have only RDS (No need to have MySQL running locally on EC2 instance). RDS takes snapshots regularly. Also, RDS is a managed service, so most of the MySQL administration tasks are handled by AWS and you don't have to worry. And you can rely on RDS snapshots from Backup perspective.