我有以下脚本来删除12个月大的快照。但这会删除所有12个月以上的快照。我必须确定12个月的孤立快照,并仅删除孤立快照而不删除AMI快照。
此脚本会删除所有12个月前的快照。
import boto
import datetime
import dateutil
from dateutil import parser
from boto import ec2
connection=ec2.connect_to_region("REGION-NAME")
ebsAllSnapshots=connection.get_all_snapshots(owner='16-DIGIT-AWS-ACCOUNT-NUMBER')
#Get the 30 days old date
timeLimit=datetime.datetime.now() - datetime.timedelta(days=365)
for snapshot in ebsAllSnapshots:
if parser.parse(snapshot.start_time).date() <= timeLimit.date():
print " Deleting Snapshot %s %s " %(snapshot.id,snapshot.tags)
connection.delete_snapshot(snapshot.id)
else:
# this section will have all snapshots which is created before 30 days
print "Only Deleting Snapshots which is 365 days old"