Skip to content

Instantly share code, notes, and snippets.

@chrissiefken
Created December 22, 2014 15:07
Show Gist options
  • Select an option

  • Save chrissiefken/bdda397583416cd59547 to your computer and use it in GitHub Desktop.

Select an option

Save chrissiefken/bdda397583416cd59547 to your computer and use it in GitHub Desktop.
PHP to snapshot a list of EBS volumes
<?php
require '/usr/share/pear/AWSSDKforPHP/aws.phar';
use Aws\Ec2\Ec2Client;
$zone = '<zone>';
$aws_creds = array(
'key' => '<key>',
'secret' => '<secret>',
'region' => $zone
);
$client = Ec2Client::factory($aws_creds);
$volumes = array(
'mysql-sdf'=>'<volume-id>', // use description to help ID the drive's server and mountpoint
'mysql-sda1'=>'<volume-id>',
'website-sda1'=>'<volume-id>'
);
foreach ($volumes as $name => $volume) {
$result = $client->createSnapshot(array(
'DryRun' => false,
'VolumeId' => $volume,
// set up the description as auto-servername-time we will use auto* to find and delete rolling snapshots
'Description' => 'auto-' . $name . '-' . time(),
));
echo $name . ' ' . $volume . '\n';
}
@chrissiefken
Copy link
Author

See also deleting rolling snapshots:
https://gist.github.com/chrissiefken/aa08a2633edb0ea9e993

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment