Created
December 22, 2014 15:07
-
-
Save chrissiefken/bdda397583416cd59547 to your computer and use it in GitHub Desktop.
PHP to snapshot a list of EBS volumes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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'; | |
| } | |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See also deleting rolling snapshots:
https://gist.github.com/chrissiefken/aa08a2633edb0ea9e993