-
Notifications
You must be signed in to change notification settings - Fork 0
/
RunEBSSnapshot.py
63 lines (39 loc) · 1.76 KB
/
RunEBSSnapshot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import datetime
from Class.EBSSnapshotClass import EBSSnapshotClass #from Class import *
from Class.EBSConnectClass import EBSConnectClass #from Class import *
#import sys, getopt, boto
#from boto.ec2.image import Image
#from boto.ec2.image import ImageAttribute
#from boto.ec2.key import Key
#from datetime import datetime, date, time
#from collections import defaultdict
if __name__ == "__main__":
import sys
if len(sys.argv) <= 4:
print "Usage: python ebs_snapshot.py instance_id, number_of_backups_to_keep, description and AMI filter"
print "All arguments are required."
sys.exit(1)
instid = sys.argv[1]
keep = int(sys.argv[2])
desc = sys.argv[3]
amifilter = sys.argv[4]
#print instid + ' ' + str(keep) + ' ' + desc + ' ' + amifilter
#exit()
#Parameters, substitute your own below
amiownerid = '' #AWS owner ID goes here
now = datetime.datetime.now()
#print 'Program Start ' + now.strftime("%Y-%m-%d %H:%M") #now = datetime.datetime.now()
timestamp = now.strftime("%Y%m%d_%H%M%S")
#print timestamp
myEBSSnapshot = EBSSnapshotClass()
myEBSConnect = EBSConnectClass()
myec2_conn = myEBSConnect.connect()
print myec2_conn
#print instid + ' ' + str(keep) + ' ' + desc
params = [myec2_conn, instid, keep, desc]
print 'params: ' + str(params)
myEBSSnapshot.backup_instance(params, amiownerid, amifilter)
#After you create an AMI above, it is counted as one of AMIs that is retained by the line below
myEBSSnapshot.del_older_ami(params, amiownerid, amifilter)
#backup_volumes(myparams)
exit()