Automatic Backup of AWS instances

14 May 2016

There is no builtin option in AWS to backup instances automatically, so I created a ruby script that can run from crontab and create automatic AMI images from ec2 instances.

aws_ami_autobackup.rb works with ec2 tags, the script get tag and value and create AMI from all instances that has this tag and value.

Here is how to install and use the script


vi ~/.aws/credentials
aws_access_key_id = XXXXXXXXXXXXXXXXXXXX

How To Use aws_ami_autobackup.rb

Here are few examples on how to use the tool:

/usr/local/bin/aws_ami_autobackup.rb -t daily_backup -v true -r us-east-1 -x 7
for i in dev qa test; do /usr/local/bin/aws_ami_autobackup.rb -t daily_backup -v true -r us-east-1 -x 7 -p ${i}; done
00 00 * * * /usr/local/bin/aws_ami_autobackup.rb -t daily_backup -v true -r us-east-1 -x 7

Now you just need to add the right tags to your instances and test it :)