Automating Linux EBS snapshots backup and clean-up

前端 未结 2 2008
轻奢々
轻奢々 2021-01-14 15:34

Are there any good updated shell scripts for EBS snapshots to S3, and clean-up of older snapshots?

I looked through SO, but mostly are from 2009, referring to link t

相关标签:
2条回答
  • 2021-01-14 16:17

    Try the following shell-script, I use this to create snapshot for most of my projects and it works well.

    https://github.com/rakesh-sankar/Tools/blob/master/AmazonAWS/EBS/EBS-Snapshot.sh

    You can give me pull-request/fork the project to add the functionality of cleaning-up the old entries. Also watch for this repo, when I find some time I will update the code to have clean-up functionality.

    0 讨论(0)
  • 2021-01-14 16:29

    If it is ok to use PHP as shel script you can use my latest script with latest AWS PHP SDK. This is much simpler because you do not need to setup environment. Just feed script your API keys.

    How to setup

    1. Open SSH connection to your server.
    2. Navigate to folder

      $ cd /usr/local/
      
    3. Clon this gist into ec2 folder

      $ 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 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
      
    0 讨论(0)
提交回复
热议问题