Skip to content
Script for automatic snapshots of AWS EC2 instances
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information. ADHOC fix (Snapshots-Tagging): Fix tagging snapshots by constructing May 8, 2019

Automatic backups for AWS instances

This script provides functionality to create automatic snapshots of AWS EC2 instances and to rotate them by deleting the snapshots older than a given amount of days.


  1. Create an ec2 iam role ( having at least the following inline policy:
    "Version": "2012-10-17",
    "Statement": [
            "Sid": "Stmt1403767721000",
            "Effect": "Allow",
            "Action": [
            "Resource": [
  1. Assign the role created above to the target server, alternative (this is way worse approach cause it might expose your AWS credential to general public): Define following environment variables containing the credentials of the new user:

    • $AWS_BACKUP_SECRET_KEY, i.e. ****************************************
  2. Install the aws cli on the target server

  3. By default the snapshots older than 30 days are deleted. If you want to change it, you can adjust the variable $daysToKeep at the beginning of the script

  4. Run and enjoy

  5. If you want to run this script as a cron job, please add following line to the root's cronjobs (with your path to the script):

       01 01 * * * /bin/bash /home/ec2-user/aws-backup/
You can’t perform that action at this time.