Last active
February 15, 2016 11:02
-
-
Save awaddell/b1bc477d265e705a4e65 to your computer and use it in GitHub Desktop.
Backup RDS automatic snapshots with manual ones that don't get deleted along with the instance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
: "${mysqlhost:?Need to set mysqlhost}" | |
# example JMESPath input to --query | |
# 'DBSnapshots[?starts_with(DBSnapshotIdentifier,`rds:mysql-master-2016-02-14`)==`true`]' | |
mydate=`date -u +%Y-%m-%d` | |
region=`curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone | sed 's/\(.*\)[a-z]/\1/'` | |
querypre='DBSnapshots[?starts_with(DBSnapshotIdentifier,' | |
querypost=')==`true`].DBSnapshotIdentifier' | |
query=$querypre\`rds:$mysqlhost-$mydate\`$querypost | |
# echo "using query: $query" | |
autosnapshot=`aws --region $region rds describe-db-snapshots \ | |
--snapshot-type "automated" \ | |
--db-instance-identifier $mysqlhost \ | |
--query $query \ | |
--output text` | |
if [ -v autosnapshot ]; then | |
echo "found $autosnapshot" | |
autosnapshotcopy=`echo "$autosnapshot" | sed 's/rds://' | sed 's/$/-copy/'` | |
echo "copying to $autosnapshotcopy" | |
aws --region $region rds copy-db-snapshot \ | |
--source-db-snapshot-identifier $autosnapshot \ | |
--target-db-snapshot-identifier $autosnapshotcopy | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment