Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
This script takes a snap shot of volume in AWS.
<?php
// Include the SDK using the Composer autoloader
require '/AWS_LIB_PATH/aws-autoloader.php';
use Aws\Common\Aws;
/// Create a service locator using a configuration file
$aws = Aws::factory(array(
'region' => 'eu-west-1', // define zone here
'key' => 'API KEY', // define your api key here
'secret' => 'API SECRET', // define your api secret here
));
$ec2Client = $aws->get('ec2');
$result = $ec2Client->createSnapshot(array(
//'DryRun' => true || false,
// VolumeId is required
'VolumeId' => 'VOLUME ID', // define volume id
'Name' => 'Auto Backup',
'Description' => 'Backup Generated at '. date('F j, Y, H:i:s'),
));
//Save this script and in cron I added this entry to run every night
//30 2 * * * php /home/meraj/aws-volume-backup.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment