GithubHelp home page GithubHelp logo

aws-automatic-snapshots's Introduction

AWS Automatic Snapshots

This script performs automatic snapshots (backups) of tagged EBS volumes, with configurable periodicity and retention policies.

Features

  • Easy to use, it leverages AWS's tags to select the volumes to back up
  • Written in Python, it's easy to customize and install using Cron
  • It support "before" and "after" hooks, which can be used to lock and unlock a database or filesystem
  • It supports unlimited, fine-grained custom policies. For example:
    {
        "CRITICAL": {     # Tag your data volume as "AUTO-SNAPSHOT" : "CRITICAL" to activate the automatic backups
            "hour":   2,  # Create a snapshot each hour, keep the last two, and delete the rest
            "day":    5,  # Create a snapshot each day, keep the last five, and delete the rest
            "week":  52,  # Create a snapshot each week, keep the last 52, and delete the rest
            "month":  0,  # Don't make a monthly snapshot, and delete any existing snapshots for this policy and period
            "only_attached_vols": True,  # Only snapshot volumes which are attached to the current instance
            "hook_module": "/usr/local/bin/flush_and_lock_mysql.py"  # A module with "before" and "after" hooks
        },
        "MEH": {
            "hour":   0,
            "day":    0,
            "week":   0,
            "month":  1,
            "only_attached_vols": True,
            "hook_module": None
        },
        ...
    }

Usage

  • Create the following IAM policy using the AWS Console and assign it to a user:
    {
        "Statement": [
            {
                "Sid": "Stmtxxxxxxxxxxxxx",
                "Effect": "Allow",
                "Action": [
                    "ec2:CreateSnapshot",
                    "ec2:CreateTags",
                    "ec2:DeleteSnapshot",
                    "ec2:DescribeSnapshots",
                    "ec2:DescribeTags",
                    "ec2:DescribeVolumeAttribute",
                    "ec2:DescribeVolumeStatus",
                    "ec2:DescribeVolumes"
                ],
                "Resource": [
                    "*"
                ]
            }
        ]
    }
  • Edit the script and customize the configuration

  • Optionally, create a Python script that defines the following functions:

    aws_automatic_snapshots_before(period, policy, volume)
    aws_automatic_snapshots_after(period, policy, volume, snapshot)
  • Tag your EBS Volumes with the policies you have defined. For example: "AUTO-SNAPSHOTS" : "CRITICAL"

  • Edit Crontab to execute your script periodically:

# chmod +x aws-automatic-snapshots.py
# crontab -e
@hourly /usr/local/bin/aws-automatic-snapshots.py hour
@daily /usr/local/bin/aws-automatic-snapshots.py day
@weekly /usr/local/bin/aws-automatic-snapshots.py week
@monthly /usr/local/bin/aws-automatic-snapshots.py month

Dependencies

Copyright

Joel Santirso, 2015

License

This projected is licensed under the terms of the MIT license.

aws-automatic-snapshots's People

Contributors

jsantirso avatar

Stargazers

Ladislav Prskavec avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.