-1

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.

AnchovyLegend
  • 12,139
  • 38
  • 147
  • 231
  • RDS already has an automatic backup feature. What specifically are you trying to accomplish beyond that? – Mark B Dec 11 '17 at 15:47
  • Hi Mark. I need to automate the backing up of RDS instances every specified time interval and also need to delete RDS backups older than a week. – AnchovyLegend Dec 11 '17 at 15:48
  • What time interval? – Rodrigo Murillo Dec 11 '17 at 16:28
  • @AnchovyLegend RDS has that capability built-in. You can pick how many days you want to keep backups, and you can pick a backup time window. – Mark B Dec 11 '17 at 16:34
  • @markb I believe that is a fixed once per day schedule. Some use cases or backup policies may require a more frequent interval? Or are some of these RDS backup lambda from days before automated snapshots were available? – Rodrigo Murillo Dec 11 '17 at 16:43
  • @AnchovyLegend that Lambda is for creating AMI images, not RDS snapshots just FYI. – Rodrigo Murillo Dec 11 '17 at 16:47
  • @RodrigoM which is why I'm asking AnchovyLegend what exactly his needs are that aren't provided by the features built into RDS. – Mark B Dec 11 '17 at 16:47

3 Answers3

1

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?

Rodrigo Murillo
  • 13,080
  • 2
  • 29
  • 50
0

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

Joseph
  • 512
  • 2
  • 5
0

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")
        }
    })
    }        
})
Krismorte
  • 642
  • 7
  • 24