2017-03-08 3 views

Antwort

1

Dies könnte hilfreich sein. Es ist ein Python-Programm, das ich geschrieben habe, das Snapshots aller Volumes macht und die letzten 2 Snapshots behält.

Sie könnten ein Programm wie dieses auf einer EC2-Instanz ausführen oder es so konvertieren, dass es als geplante AWS-Lambda-Funktion ausgeführt wird.

#!/usr/bin/env python 

import boto.ec2, os 

MAX_SNAPSHOTS = 2 # Number of snapshots to keep 

# Connect to EC2 in this region 
connection = boto.ec2.connect_to_region('<insert region here>') 

# Get a list of all volumes 
volumes = connection.get_all_volumes() 

# Create a snapshot of each volume 
for v in volumes: 
    connection.create_snapshot(v.id) 

    # Too many snapshots? 
    snapshots = v.snapshots() 
    if len(snapshots) > MAX_SNAPSHOTS: 

    # Delete oldest snapshots, but keep MAX_SNAPSHOTS available 
    snap_sorted = sorted([(s.id, s.start_time) for s in snapshots], key=lambda k: k[1]) 
    for s in snap_sorted[:-MAX_SNAPSHOTS]: 
     print "Deleting snapshot", s[0] 
     connection.delete_snapshot(s[0]) 
Verwandte Themen