Friday, August 22, 2014

How to take scheduled back up of AWS RDS snapshots

Amazon provides us with option of Automated backup but if in case you need to take scheduled manual back up than following script can be used..

In the script we are considering the scenario of taking monthly backup on 1st of every month from the daily automated RDS snapshots..


# The script to take monthly backup of DB snapshots
# By Ravi Gadgil

#Following command will find the snapshot identifier from the DB that need to be manually copied..
aws rds describe-db-snapshots --db-instance-identifier DB-server-name1 | grep `date +%Y-%m-01` | grep rds | awk '{ print $8 }' > /tmp/DB-server-name1.txt

aws rds describe-db-snapshots --db-instance-identifier DB-server-name2 | grep `date +%Y-%m-01` | grep rds | awk '{ print $8 }' > /tmp/DB-server-name2.txt

aws rds describe-db-snapshots --db-instance-identifier DB-server-name3 | grep `date +%Y-%m-01` | grep rds | awk '{ print $8 }' > /tmp/DB-server-name3.txt

#Following command will take the snapshot identifier from above command and copy it..
aws rds copy-db-snapshot --source-db-snapshot-identifier `cat /tmp/DB-server-name1.txt` --target-db-snapshot-identifier DB-server-name1-monthly-backup-`date +%Y-%m`

aws rds copy-db-snapshot --source-db-snapshot-identifier `cat /tmp/DB-server-name2.txt` --target-db-snapshot-identifier DB-server-name2-monthly-backup-`date +%Y-%m`
aws rds copy-db-snapshot --source-db-snapshot-identifier `cat /tmp/DB-server-name3.txt` --target-db-snapshot-identifier DB-server-name3-monthly-backup-`date +%Y-%m`

We are running the above script on the 2nd of every month so it can take DB snapshot of one day old and backup it..

We have define the DB names individully in commands but you can use for loop as well if list is very big in your case..

Note : You need to have AWS CLI installed in you server to get this script running fine if in case you don't have that follow the following link.

Setup fully configurable EFK Elasticsearch Fluentd Kibana setup in Kubernetes

In the following setup, we will be creating a fully configurable Elasticsearch, Flunetd, Kibana setup better known as EKF setup. There is a...