How to set up automatic disk backups

    When using AWS EC2, I found that there is no ready-made interface for creating disk backups, which in AWS are called Snapshot.

    I began my research on how to set up automatic updates. I re-read a lot of material, and came to the conclusion that there is no simple solution. You need to read a lot of documentation to set everything up. I understand that without this, no where. Reading docks is a big part of the life of both a developer and an administrator. But sometimes, everything can be much simpler, and you do not need to spend a lot of time on what can be done in just a few minutes.

    I propose my 10-step setup without installing AWS Command Line Tools.

    It is assumed that the team gitand wgetavailable.

    Step 1

    Open SSH and go to the folder.

    $ cd /usr/local/
    

    Step 2

    We copy the finished code that I created and which is located on the github to the folder ec2.

    $ git clone https://gist.github.com/9738785.git ec2
    

    Step 3

    And go to this folder.

    $ cd ec2
    

    Step 4

    We make the file backup.phpexecutable.

    $ chmod +x backup.php
    

    Step 5

    Now you need to open the AWS PHP SDK releases page on github, copy the link for the latest release on the green download button. And now download it to disk.

    $ wget https://github.com/aws/aws-sdk-php/releases/download/2.6.0/aws.zip
    

    Step 6

    Unzip the archive into the aws folder.

    $ unzip aws.zip -d aws 
    

    Step 7

    Edit the file backup.php. We are interested in lines from 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";
    


    I think that the settings are clear to everyone. Be sure to specify the region. If you have several disks, then you can add them all to the array.

    Step 8

    Let's check how it works.

    $ ./backup.php
    

    Step 9

    Open the AWS control panel and verify that Snapshot has been created.

    Step 10

    Add the task in crowns. And it doesn’t matter how often it will be executed. Even if you put it once a minute, snapshot will be created only at the specified time in the settings. But of course, if you specified in the settings 12 hoursand the task of crowns was set once every 24 hours, then this will not work. You need to make sure that the cron task works according to the settings. For my example, once every 24 hours is enough.

    * 23 * * * /usr/local/ec2/backup.php
    

    Also popular now: