Giter Site home page Giter Site logo

php-aws-snapshots's Introduction

Delete AWS snapshots, keeping only the latest number of snapshots specified

Requirements

  • AWS CLI
  • AWS IAM snapshot permissions (example policy)
  • PHP 5.3+
  • Access to crontab (or some other job scheduler)

Setup

This assumes you've already installed and setup AWS CLI and added the correct IAM permissions within your AWS console.

1. Create PHP file to load class and hold snapshot configuration

<?php
require_once('snapshots.php');
$volumes = array(
   'vol-123af85a' => array('keep' => 7)
);
$snapshots = new DeleteSnapshots($volumes);
$snapshots->run();

2. Add cron job

The cron job schedule will depend on your configuration. The class honors the interval setting, but you may not want it to run every minute of every day when you just need a nightly backup.

# run every night at 3:00 am
00	03	* * * /usr/bin/php /root/scripts/run-snapshots.php

Volume Configuration

Name Type Description
volume id string AWS EBS volume ID
keep integer total number of snapshots to store for volume

Example IAM Policy

This is a minimal policy that includes ONLY the permissions needed to work. You could also limit the "Resources" option to restrict it even further.

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "ec2:DeleteSnapshot",
        "ec2:DescribeSnapshots"
      ],
      "Resource": [
        "*"
      ]
    }
  ]
}

Fresh install on Ubuntu 14.04

sudo apt-get install python-pip php5-cli
sudo pip install awscli

// must set region - ie: us-east-1, us-west-1
aws configure

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.