Lambda RDS backups - amazon-web-services

I am working on a project that requires the automated backing up of two RDS instances. What would be the best way to accomplish this?
I was thinking to create a lambda function that backs up all RDS's with a tag 'Backup', similar to what I have going for EC2.
I appreciate any suggestions on how to accomplish this.

Here is a good example of an RDS maintenance Lambda for managing automated RDS backups from Lambda: https://github.com/cevoaustralia/aws-backup-lambda
As stated in the comments, RDS has a daily automated backup built into the service, but if you need a different or more frequent schedule, then you can use Lambda to automate the backups.
That project states:
A utility AWS lambda function to manage EBS and RDS snapshot backups.
The Lambda function takes new backups when executed, and manages the
deletion of the old ones when the upper limit is reached.
Beyond the RDS auto backups, a different/dedicated Lambda to copy snapshots is handy if you want to automate copying those snapshots to a different region for disaster recovery.
Using the above Lambda to schedule your snapshots, this Lambda will periodically copy the most current snapshot to another region, and prune old snapshots in the 'foreign' region. See https://github.com/pbudzon/aws-maintenance.
Also please see this answer on pros/cons of relying on RDS snapshots vs native backup: Should I stick only to AWS RDS Automated Backup or DB Snapshots?

RDS has automated snapshots, but you can copy those snapshots.
This tutorial shows how to automate the copy across regions, but could be easily modified to copy it to the same region.
It includes all the code needed as well as step by step instructions and a video walk through!
https://geektopia.tech/post.php?blogpost=Automating_The_Cross_Region_Copy_Of_RDS_Snapshots

RDS has automated backup out-of-the-box but this expire in 35 days so you can copy theses automated backups and its become manually without expire date. I wrote a article talking about this and I publish a project on github too
https://medium.com/#krisnamourt.filho/aws-rds-backup-strategy-f0cd1e0ac10f
https://github.com/krismorte/lambda-rds-snapshot
this is the example to copy rds snapshots
var cluster = await rdsFunc.describeClusters();
cluster.forEach(async (cluster)=>{
var snaps = await rdsFunc.describeClustersAutomatedSnapshot(cluster.DBClusterIdentifier)
if(snaps){
snaps.forEach(async (snap)=>{
var copyDate = dateFunc.minusDaysFromToday(daysBefore);
var snapshotDate = dateFunc.removeTimeFromDate(snap.SnapshotCreateTime);
if (copyDate == snapshotDate) {
var copy = await rdsFunc.copyClusterSnapshot(snap.DBClusterSnapshotIdentifier)
console.log(copy+" Rds cluster snapshot cloned")
}
})
}
})

Related

restoring aurora cluster from s3 or restoring from snapshot

well I have couple of questions. I have a aurora cluster with a single MySQL RDS instance which has 450GB of data. we use this cluster only when we are doing some specific testing.so I want to delete this cluster but keep its data available to me so I can make a new cluster whenever we need any testing to be done.
there are couple of ways this can be done as far as I know
take a snapshot of the cluster and restore the cluster from the
snapshot whenever required.
backup the cluster to s3 and restore the
cluster from s3 when required
which way is more faster and which one is more cost efficient?
can an entire cluster be restored from s3 if so what are the steps involved ? , I found the aws documentation bit too messy.
If we stop a aurora cluster, it again automatically restarts within 7 days , is there a way to prevent this automatic restart and keep it stopped when it is not required and start when required ?

AWS RDS disaster recovery using cross-account

We are running AWS RDS PostgreSQL, with daily automatic snapshots, encrypted by AWS managed KMS key. My objective is to minimize risks and data loss, in case when main AWS account (running RDS) got compromised or RDS deleted/damaged in some way.
What we've implemented so far: RDS snapshots are shared with different (backup) account, periodically copied to backup account and re-encrypted with the KMS key from the backup account, to make copies local, and independent from the main AWS account.
I'm wondering if there are better ways to minimize recovery time objective and recovery point objective in case of a disaster event?
This AWS blog post seems to weigh the options well.
Automated backups are limited to a single AWS Region while manual snapshots and Read Replicas are supported across multiple Regions.
Having cross region Read replica would give you the best RPO and RTO as you can promote replica to be an independent instance which should improve your RPO / RTO
Alternatively, if you choose to use Amazon Aurora Backtrack it seems to offer a similar option to having a read replica but I do not have a personal experience with this feature so can't say how effective it is in improving RTO and RPO.
I wrote two scripts implementing flow at the diagram drawn above ^^^, the idea is to run them daily:
src_acc_take_share_rds_snapshot.py in src account:
list available RDS snapshots according to provided regexp
recrypt them with KMS key, shared from dst account
share recrypted RDS snapshots with the dst account
remove old decrypted snapshots
dst_acc_copy_shared_rds_snapshot_to_local.py in dst account
list RDS snapshots, shared in src account with dst account
copy RDS snapshots from src account to dst account
remove old decrypted snapshots
fire an SNS message if desired snapshot count != actual
and put them at GitHub https://github.com/mvasilenko/dr-rds-share-snapshot

AWS RDS Automated Backup and Snapshots - how to make both?

I'm familiar with the differences between "Automated Backups" and Snapshots. I'm trying to backup using both of them, but from the Modify-section of DB I find only Backup and Backtrack, and to my understanding, the backups from the Backup-section ( https://i.imgur.com/LwdMy8T.png ) should be going under "Automated Backups", right? But they're going under Automated Snapshots.
How do I create Automated Backup instead of snapshot?
E. I'm Using Amazon Aurora, I suppose that makes it a little different than other RDS!
Automated backups are always enabled on Amazon Aurora DB Instances.
Firstly to understand the difference between a snapshot & an automated backup:
Amazon RDS creates and saves automated backups of your DB instance. Amazon RDS creates a storage volume snapshot of your DB instance, backing up the entire DB instance and not just individual databases.
Both of which are automatically active when you create an RDS unless you specify otherwise while creating the RDS instance:
Secondly regarding your amazon aurora question, it does the same thing as a normal RDS creating automated backups & snapshots:
Automated backups are always enabled on Amazon Aurora DB Instances. Backups do not impact database performance.
References: https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_WorkingWithAutomatedBackups.html
https://aws.amazon.com/rds/aurora/faqs/#Backup_and_Restore

Terraform destroying RDS instance and retaining automated backups

I have created and I have been managing a Postgresql RDS instance using Terraform.
Assuming I perform a terraform destroy, will this also delete the associated RDS snapshots that have been taken via the RDS schedule?
Terraform added the option to keep the automated backups for an RDS with the delete_automated_backups flag. Just set this to false.
When destroying an RDS database you have the option to either create a long lived final snapshot or retain the automated backups which will be deleted as per the schedule they were set for:
Instead of creating a snapshot, you can choose to enable Retain automated backups when you delete a DB instance. These backups are still subject to the retention period of the DB instance and age out the same way systems snapshots do.
Terraform supports keeping a final snapshot by setting the final_snapshot_identifier and making sure that skip_final_snapshot is not set to true.
Unfortunately, Terraform doesn't currently support retaining the automated backups taken from scheduled snapshots but there is an open feature request with a couple of half finished pull requests linked to it.

Best option to take complete Backup of EC2 instance?

Currently I am taking manual backup of our EC2 instance by zipping the data and downloading it locally as well as on DropBox.
But I am wondering, can I have an option where I just take a complete copy of the whole system automatically daily so if something goes wrong/crashes, I can replace it with previous copy immediately rather than spending hours installing and configuring things ?
I can see there is an option of take "Image" but can I automated them to have just 1 latest image and replace the system with single click ?
You can create a single Image of your instance as Backup of your instance Configuration.
And
To keep back up of your data you can use snapshots of your volumes.
snapshots store data in incremental format whenever you make any changes.
When ever needed you can just attach the volume from the snapshot to your Instance.
It is not a good idea to do "external backup" for EC2 instance snapshot, before you read AWS pricing details.
First, AWS is charging every GB of data your transfer OUTside AWS cloud. Check out this pricing. Generally speaking, after the 1st GB, the rest will be charge at least $0.09/GB, against S3-standard pricing ~ $0.023/GB.
Second, the snapshot created is actually charges as S3 pricing(Check :
Copying an Amazon EBS Snapshot), not EBS pricing. After offset the transfer cost, perhaps you should consider create multiple snapshot than keep doing the data transfer out backup.
HOWEVER, if you happens to use an instance that use ephemeral storage, snapshot will not help. You need to copy the data out from ephemeral storage yourself. Then it is your choice to store under S3 or other place.
Third. If you worry the AWS region going down, check the multiple AZ option. Or checkout alternate AWS region option.
Fourth. When storing backup data in S3, you can always store them under Infrequent-Access, which save you some bucks, and you don't need to face an insane Glacier bills during emergency restore(Avoid Glacier, unless you are pretty sure about your own requirement).
Fifth, after done your plan of doing everything inside AWS, you can write bash script (AWS CLI) or use boto3, etc API to do the automatic backup.
Lastly , here is way of AWS create and maintain snapshot. Though each snapshot are deem "incremental", when u delete old snap shot :
the snapshot deletion process is designed so that you need to retain
only the most recent snapshot in order to restore the volume.
You can always "test" restore by create another EC2 instance that load the backup snapshot. Or you can mount the snapshot volume from another EC2 instance to check the contents.