-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrds_snapshots.py
More file actions
59 lines (41 loc) · 1.74 KB
/
Copy pathrds_snapshots.py
File metadata and controls
59 lines (41 loc) · 1.74 KB
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
import os
import json
import boto3
from utils.session import get_session
from utils.regions import get_all_regions
from utils.json_encoder import json_encoder
from utils.json_writer import json_writer
from utils.json_printer import json_printer
def get_shapshots_for_region(client):
paginator = client.get_paginator('describe_db_snapshots')
for page in paginator.paginate():
for shapshot in page['DBSnapshots']:
yield shapshot
def get_snapshot_attributes(client, snapshot_id):
return client.describe_db_snapshot_attributes(DBSnapshotIdentifier=snapshot_id)['DBSnapshotAttributesResult']
def main():
session = get_session()
all_data = {}
for region in get_all_regions(session):
all_data[region] = {}
client = session.client('rds', region_name=region)
for snapshot in get_shapshots_for_region(client):
snapshot_id = snapshot['DBSnapshotIdentifier']
print('Region: %s / Snapshot: %s' % (region, snapshot_id))
try:
attributes = get_snapshot_attributes(client, snapshot_id)
except Exception as e:
msg = 'Failed to retrieve attributes for %s @ %s. Error: "%s"'
args = (snapshot_id, region, e)
print(msg % args)
attributes = {}
all_data[region][snapshot_id] = {}
all_data[region][snapshot_id]['main'] = snapshot
all_data[region][snapshot_id]['attributes'] = attributes
else:
print('Region: %s / No snapshots found' % (region,))
os.makedirs('output', exist_ok=True)
json_writer('output/rds-snapshots.json', all_data)
json_printer(all_data)
if __name__ == '__main__':
main()