Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to setup automatic scheduled snapshots for each single AMI/EBS?

Does Amazon support any kind of automatic scheduled snapshots that can be configured for each single AMI/EBS?

my goal is to have each AMI backup itself regularly without relying on external scripts and similar.

like image 301
Faris Zacina Avatar asked Oct 23 '12 11:10

Faris Zacina


People also ask

How do you automate EBS snapshots?

To create an automated snapshot lifecycle policy, you need to first select Lifecycle Manager from your EC2 dashboard. Under Policies, select Create Snapshot Lifecycle Policy. From there, you can enter the details of your policy.

How do I create a snapshot periodically in AWS?

To create a snapshot policyOpen the Amazon EC2 console at https://console.aws.amazon.com/ec2/ . In the navigation pane, choose Elastic Block Store, Lifecycle Manager, and then choose Create lifecycle policy. On the Select policy type screen, choose EBS snapshot policy and then choose Next.

Does AMI create snapshot?

During the AMI-creation process, Amazon EC2 creates snapshots of your instance's root volume and any other EBS volumes attached to your instance. You're charged for the snapshots until you deregister the AMI and delete the snapshots.


2 Answers

You can use the AWS command-line tools to automate EBS snapshots. Just schedule a cron job or similar to run ec2-create-snapshot command at the desired interval on your ebs volume.

You can also make API calls over http to do the same thing, if you don't want to install the command line tools.

See the link for more information on creating EBS snapshots.

http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/ebs-creating-snapshot.html

like image 121
Mike Brant Avatar answered Oct 28 '22 02:10

Mike Brant


use this python code

from boto.ec2.connection import EC2Connection
from datetime import datetime
import sys

if __name__ == '__main__':

    conn = EC2Connection('aws_access_key_id', 'aws_secret_access_key')

    volumes_id={'vol-2354534'}

    description = 'Created by crontab  at ' + datetime.today().isoformat(' ') 

    for vol_id in volumes_id :

        snapshot  = conn.create_snapshot( vol_id ,description)        
like image 35
Saurabh Chandra Patel Avatar answered Oct 28 '22 01:10

Saurabh Chandra Patel