Skip to content

Instantly share code, notes, and snippets.

@cam-gists
Created November 12, 2012 17:31
Show Gist options
  • Save cam-gists/4060701 to your computer and use it in GitHub Desktop.
Save cam-gists/4060701 to your computer and use it in GitHub Desktop.
PHP / Shell / AWS: snapsot backup
#!/usr/bin/php
<?php
// Pear Lib
require_once "XML/Unserializer.php";
$options = array(
                        'complexType' => 'object',
                        'encoding' => 'utf-8',
                        'parseAttributes' => TRUE,
                        'returnResult' => TRUE
                );
$xr = new XML_Unserializer($options);
$volumes = array(
        "xxxxxxxx" => "OS-Image-Production",
        "xxxxxxxx" => "Data-Production",
        "xxxxxxxx" => "OS-Image-Dev",
        "xxxxxxxx" => "Data-Dev"
        );
foreach($volumes as $vol_name => $descrip)
{
        shell_exec("/usr/bin/aws --xml create-snapshot vol-".$vol_name." --description ".date("Y-m-d")."_".$descrip);
//      print "/usr/bin/aws --xml create-snapshot vol-".$vol_name." --description ".date("Y-m-d")."_".$descrip."\n";
}
$aws_snapshots = shell_exec("/usr/bin/aws --xml describe-snapshots");
$aws_snapshots = $xr->unserialize($aws_snapshots);
if($aws_snapshots)
{
        foreach($aws_snapshots->snapshotSet->item as $snap)
        {
                if($snap->snapshotId != "snap-b5d2dbd8" AND strtotime($snap->startTime) < strtotime("-14 day"))
                {
//                      print "/usr/bin/aws --xml delete-snapshot ".$snap->snapshotId."\n";
                        shell_exec("/usr/bin/aws --xml delete-snapshot ".$snap->snapshotId);
                }
        }
}
// TIm K cmd line script // AWS command line
//http://timkay.com/aws/
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment