Blog

AWS LightSail Automatic Snapshots

Tags: awsbackupLightSailsnapshot

Published on: November 27, 2019 by Shafeer P

AWS LightSail Automatic Snapshots

Scenario:

Preface

AWS LightSail provides cheap VPS hosting compared to EC2, with a simple management interface.

LightSail allows us to create entire disk snapshots for reliability and portability. If you have a number of LightSail VPSs, managing the snapshots is a kinda headache for sure. So, we have written a shell script with the help of AWS CLI API to create and delete snapshots according to user’s preference, automatically.

The Shell Script

The script was originally written by Govind Raj and further improved by Shafeer P. The current version is kept in our GitHub repository.

Installation and Configuration

  1. Create an IAM programmatic user with the following permissions for the service LightSail:
    GetRegions
    GetInstance
    GetInstances
    GetDiskSnapshot
    GetDiskSnapshots
    GetInstanceSnapshot
    GetInstanceSnapshots
    GetDisk
    CreateDiskSnapshot
    CreateInstanceSnapshot
    DeleteInstanceSnapshot

    If you are unsure, create a user with LightSail full access. Note down the ACCESS_KEY and SECRET_KEY which we require in the next steps.

  2. Create KEY-VALUE pair tags for instances to take automatic backups.
    KEY  VALUE TYPE DEFAULT VALUE NOTES
    backup.enable true Boolean NULL Case-sensitive. Any value other than true will disable automatic backups.
    If disabled, existing backups won’t be removed automatically.
    backup.retention [0-9] Digit 1

    Maximum number of backups kept which created with name suffix snapof-

    The value 0 will remove all backups.

  3. Install the AWS CLI on a Linux machine
  4. Place the backup script in the Linux machine with AWS CLI installed, and modify the ACCESS_KEY, SECRET_KEY you have generated in Step 1.
  5. Give necessary permissions to the script and create a crontab entry according to your preferred schedule.

Default Behavior and Customization

  • The script uses ENVIRONMENT VARIABLE for AWS CLI for better portability. You can also rely on alternate methods for configuration.
  • If no retention count is specified for an instance in TAG, the default value 1 is used. You can customize this value in the script variable ret_count_default

Category : AWS

Shafeer P

Shafeer P

Shafeer is currently working as Senior System Engineer at SupportSages. He is capable of tackling time-consuming issues quickly with his advanced scripting abilities. His unchallenged expertise in solving complex issues in a cut-and-dried way makes him a dependable man in the team. The attitude and philosophy he shows on his workplace make his colleagues call him 'Mr. Perfectionist'. Furthermore, he is a travel and photography enthusiast, and loves to spend his leisure times on music and DIY arts.

You may also read:

Comments

Add new commentSIGN IN

Let's Connect

Get new updates

Categories

$0.000 items