2016-04-26 67 views
0

我试图删除对应于AMI的所有快照。我已经尝试了下面的命令。使用以下命令,我只能删除一个卷。在Boto delete_snapshot设置为True时,我们可以删除挂载在/ dev/sda1上的EBS卷。有没有办法删除AMI的所有卷?如何使用boto删除与AMI对应的所有快照

>>> conn.deregister_image('ami-xxxx', delete_snapshot=True, dry_run=False) 
True 

运行命令后,一个快照被删除,但还有一个快照仍然显示。我如何删除ami-xxxx的所有快照?

+0

最后一个是ami图像的快照,除非您注销ami图像,否则它将始终存在。 – BMW

+0

@BMW我可以使用以下命令(deregister_image('ami-xxxx',delete_snapshot = True,dry_run = False))删除与安装在/ dev/sda1上的EBS卷关联的快照。但是我无法删除与/ dev/sdf ..等相关的卷 – user6136315

回答

1

我还没有找到任何解决方案,这个问题。所以我写了一个python脚本来完成这项工作。

try: 
     list_snaps = conn.get_all_snapshots(filters={'owner_id' :'xxxxx'}) #it used to save some time if we filter by owner 
     for i in list_snaps: 
      find_ami_id = re.search(r'.* for (.*) from .*', i.description, re.M|re.I) 
      if find_ami_id: 
       if find_ami_id.group(1) == b: #b is the ami id that we were deleted 
        print "Delete the following snap id: %s" %i.id 
        conn.delete_snapshot(i.id, dry_run=False) 
        time.sleep(10) #wait for a while to delete snapshots one by one 
    except boto.exception.BotoServerError, e: 
     print e.error_message