Simple bash script using the AWS Cli to backup EBS Volumes.

I used a free tier micro EC2 Amazon AMI to act as the backup generator.

AWS Interface

1. Create new policy with permission to create snapshots:

– Security, Identity & Compliance > IAM

– Policy > Create policy

– Create Your Own Policy

– Give a relevant name and insert the following into the Policy Document:

“Statement”: [
“Action”: [
“Effect”: “Allow”,
“Resource”: [

– Save Policy

2. Create a user in IAM which has permission to create the snapshots:

 – Security, Identity & Compliance > IAM

 – Users > Add User

 – Name: e.g. backup, Select Programmatic Access > Next

 – Permissions  > Attach Policy (From above)

– Review > Create User > Take a Note or Download Keys

3. EC2 > EBS > Volumes > Select Volume > Tags >Add the following tags to the EBS Volumes you wish to Backup: Key=Backup Daily and Value=true

Amazon AMI Instance

1. Make sure AWS Cli is installed on the backup generator (pre-installed on Amazon AMI)

2. Configure the Cli

aws configure

3. Enter in access key, secret access key (from above) and default region e.g.

AWS Access Key ID [****************LNKA]: DFLKNDFO04443GDF5
AWS Secret Access Key [****************izTL]: hLHJBL78OIJLlkJHVJH87NJBNSW8Nk89NVNB5F
Default region name [eu-west-1]: eu-west-1
Default output format [None]: -hit enter here-

4. Export the latest version of the ec2-automate-backup resource from github

svn export

5. Make the executable

chmod +x

6. Setup a cron to run the script periodically and output the results to a log file

crontab -e
01 01 * * * /home/ec2-user/ec2-automate-backup/ -s tag -t “Backup-Daily,Values=true” -k 31 > /var/log/ec2-automate-backup.log 2>&1
*This command will backup EC2 volumes with the tag ‘Backup-Daily, True’ everyday at 01:01 and then purge old backups after 31 days.


For any help please comment below.

Written by Matt Cooper
Hi, I'm Matt Cooper. I started this blog to pretty much act as a brain dump area for things I learn from day to day. You can contact me at: