pythonでbotoを使っています。
Amazon EC2/EBSのSnapshotを定期的に取る
Amazon EBS Snapshotスクリプト:2606-36J
#!/usr/bin/python import sys from boto.ec2.connection import EC2Connection if(len(sys.argv) != 3): print "Usage: snapshot.py <num> <volume-id>" sys.exit() conn = EC2Connection('aws_access_key','aws_secret_access_key') region = conn.get_all_regions() conn = region[2].connect(aws_access_key_id='aws_access_key',aws_secret_access_key='aws_secret_access_key') conn.create_snapshot(sys.argv[2]) snapshot = {} for x in conn.get_all_snapshots(): if(x.volume_id == sys.argv[2]): tmp = {x.id:x.start_time} snapshot.update(tmp) snapshot = sorted(snapshot.items(), key=lambda (k, v): (v, k), reverse=True) for i in range(int(sys.argv[1]), len(snapshot)): conn.delete_snapshot(snapshot[i][0]) print 'DONE'あとはcronに登録すればOK
0 件のコメント:
コメントを投稿