Revisions
-
pserrano revised this gist
Oct 14, 2014 . 1 changed file with 5 additions and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,6 @@ This is based of https://gist.github.com/Serhioromano/9738785 gist but my fork gist give more information of snapshot description of all machines than you want make snapshot it. You need php-cli and php-curl installed on your system for execute all. How to create daily HDD/EBS snapshot of you AWS EC2 instance --- @@ -15,7 +16,7 @@ It looks like a very required and trivial task. But there is not outof the box s 3. Clon this gist $ git clone https://gist.github.com/bd4e889af66e6d31c13c.git ec2 4. Go to that folder @@ -27,7 +28,7 @@ It looks like a very required and trivial task. But there is not outof the box s 6. Open [releases](https://github.com/aws/aws-sdk-php/releases) of the AWS PHP SDK github project and copy URL of `aws.zip` button. Now download it into your server. $ wget https://github.com/aws/aws-sdk-php/releases/download/2.7.0/aws.zip 7. Unzip this file into `aws` directory. @@ -52,4 +53,4 @@ It looks like a very required and trivial task. But there is not outof the box s 10. If everything is ok just add cronjob. * 23 * * * /usr/local/ec2/backup.php -
pserrano revised this gist
Oct 14, 2014 . 2 changed files with 16 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -59,12 +59,24 @@ { continue; } $volinfo = $client->describeVolumes( array( 'VolumeIds' => array ($volume), ) ); $description = $snap_descr . ': ' . $volume; if (isset($volinfo['Volumes'][0]['Tags'][0]['Value'])){ $description .= ' | Machine: ' . $volinfo['Volumes'][0]['Tags'][0]['Value']; } $result = $client->createSnapshot( array( 'DryRun' => $dryrun, 'VolumeId' => $volume, 'Description' => $description, ) ); 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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,6 @@ This is based of https://gist.github.com/Serhioromano/9738785 gist but my gist give more information of snapshot description of all machines than you make snapshot How to create daily HDD/EBS snapshot of you AWS EC2 instance --- -
Serhioromano revised this gist
Mar 26, 2014 . 1 changed file with 15 additions and 15 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -8,42 +8,42 @@ It looks like a very required and trivial task. But there is not outof the box s 1. Opent SSH connection to your server. 2. Navigate to folder $ cd /usr/local/ 3. Clon this gist $ git clone https://gist.github.com/9738785.git ec2 4. Go to that folder $ cd ec2 5. Make `backup.php` executable $ chmod +x backup.php 6. Open [releases](https://github.com/aws/aws-sdk-php/releases) of the AWS PHP SDK github project and copy URL of `aws.zip` button. Now download it into your server. $ wget https://github.com/aws/aws-sdk-php/releases/download/2.6.0/aws.zip 7. Unzip this file into `aws` directory. $ unzip aws.zip -d aws 8. Edit `backup.php` php file and set all settings in line `5-12` $dryrun = FALSE; $interval = '24 hours'; $keep_for = '10 Days'; $volumes = array('vol-********'); $api_key = '*********************'; $api_secret = '****************************************'; $ec2_region = 'us-east-1'; $snap_descr = "Daily backup"; 9. Test it. Run this script $ ./backup.php Test is snapshot was created. -
Serhioromano revised this gist
Mar 26, 2014 . 2 changed files with 54 additions and 14 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,14 +2,14 @@ <?php date_default_timezone_set('UCT'); $dryrun = FALSE; $interval = '24 hours'; $keep_for = '10 Days'; $volumes = array('vol-********'); $api_key = 'AKIAIXXXXXXXXXXXXXXX'; $api_secret = 'IzMni.........................emQKct'; $ec2_region = 'us-east-1'; $snap_descr = "Daily backup"; require 'aws/aws-autoloader.php'; 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 charactersOriginal file line number Diff line number Diff line change @@ -1,12 +1,52 @@ How to create daily HDD/EBS snapshot of you AWS EC2 instance --- It looks like a very required and trivial task. But there is not outof the box solution in AWS. But fortunately it is easy to setup with few steps. ### How to setup 1. Opent SSH connection to your server. 2. Navigate to folder $ cd /usr/local/ 3. Clon this gist $ git clone https://gist.github.com/9738785.git ec2 4. Go to that folder $ cd ec2 5. Make `backup.php` executable $ chmod +x backup.php 6. Open [releases](https://github.com/aws/aws-sdk-php/releases) of the AWS PHP SDK github project and copy URL of `aws.zip` button. Now download it into your server. $ wget https://github.com/aws/aws-sdk-php/releases/download/2.6.0/aws.zip 7. Unzip this file into `aws` directory. $ unzip aws.zip -d aws 8. Edit `backup.php` php file and set all settings in line `5-12` $dryrun = FALSE; $interval = '24 hours'; $keep_for = '10 Days'; $volumes = array('vol-********'); $api_key = '*********************'; $api_secret = '****************************************'; $ec2_region = 'us-east-1'; $snap_descr = "Daily backup"; 9. Test it. Run this script $ ./backup.php Test is snapshot was created. 10. If everything is ok just add cronjob. * 23 * * * /usr/local/ec2/backup.php -
Serhioromano revised this gist
Mar 24, 2014 . 2 changed files with 2 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -75,6 +75,6 @@ ); } file_put_contents(__DIR__.'/db.json', json_encode($db)); return; 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 charactersOriginal file line number Diff line number Diff line change @@ -8,5 +8,5 @@ It looks like a very required and trivial task. But there is not outof the box s 1. Copy `backup.php` and `db.json` files into your server folder `/usr/local/ec2/'. 2. Set parameter in lines 5-11. 3. Download [AWS-PHP-SDK](https://github.com/aws/aws-sdk-php/releases) and put into foder `/usr/local/ec2/`. Put it so that `require 'aws/aws-autoloader.php';` points to correct file. 4. Make `backup.php` file executable with `chmod +x backup.php` and make sure PHP can write into `db.json`. 5. Now try to run file in command line `./backup.php`. Now you can add this command to cron. -
Serhioromano revised this gist
Mar 24, 2014 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -9,6 +9,7 @@ $api_key = 'AKIAIXXXXXXXXXXXXXXX'; $api_secret = 'IzMni.........................emQKct'; $ec2_region = 'us-east-1'; $snap_descr = "Daily backup"; require 'aws/aws-autoloader.php'; @@ -63,7 +64,7 @@ array( 'DryRun' => $dryrun, 'VolumeId' => $volume, 'Description' => $snap_descr, ) ); -
Serhioromano revised this gist
Mar 24, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -22,7 +22,7 @@ ) ); $db = json_decode(file_get_contents(__DIR__.'/db.json'), TRUE); $snapshots = array(); foreach($db AS $key => $snapshot) -
Serhioromano created this gist
Mar 24, 2014 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,79 @@ #!/usr/bin/php -q <?php date_default_timezone_set('UCT'); $dryrun = FALSE; $interval = '24 hours'; $keep_for = '10 Days'; $volumes = array('vol-********'); $api_key = 'AKIAIXXXXXXXXXXXXXXX'; $api_secret = 'IzMni.........................emQKct'; $ec2_region = 'us-east-1'; require 'aws/aws-autoloader.php'; use Aws\Ec2\Ec2Client; $client = Ec2Client::factory( array( 'key' => $api_key, 'secret' => $api_secret, 'region' => $ec2_region ) ); $db = json_decode(file_get_contents('/usr/local/ec2/db.json'), TRUE); $snapshots = array(); foreach($db AS $key => $snapshot) { if(!empty($snapshots[$snapshot['volume']])) { if($snapshot['time'] > $snapshots[$snapshot['volume']]['time']) { $snapshots[$snapshot['volume']] = $snapshot; } } else { $snapshots[$snapshot['volume']] = $snapshot; } if($snapshot['time'] < strtotime('- ' . $keep_for)) { $client->deleteSnapshot( array( 'DryRun' => $dryrun, 'SnapshotId' => $snapshot['id'], ) ); unset($db[$key]); } } foreach($volumes As $volume) { if((!empty($snapshots[$volume])) && ($snapshots[$volume]['time'] > strtotime('-' . $interval))) { continue; } $result = $client->createSnapshot( array( 'DryRun' => $dryrun, 'VolumeId' => $volume, 'Description' => 'Daily backup', ) ); $db[] = array( 'volume' => $volume, 'time' => strtotime($result['StartTime']), 'id' => $result['SnapshotId'] ); } file_put_contents('/usr/local/ec2/db.json', json_encode($db)); return; 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ [] 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ How to create daily HDD snapshot of you AWS EC2 instance --- It looks like a very required and trivial task. But there is not outof the box solution in AWS. But fortunately it is easy to setup with few steps. ### How to setup 1. Copy `backup.php` and `db.json` files into your server folder `/usr/local/ec2/'. 2. Set parameter in lines 5-11. 3. Download [AWS-PHP-SDK](https://github.com/aws/aws-sdk-php/releases) and put into foder `/usr/local/ec2/`. Put it so that `require 'aws/aws-autoloader.php';` points to correct file. 4. Make `backup.php` file executable with `chmod +x backup.php` 5. Now try to run file in command line `./backup.php`. Now you can add this command to cron.