Created
May 11, 2022 20:48
-
-
Save brianrogers/b33dbb7e1b2e97d3020acc45c40e378e to your computer and use it in GitHub Desktop.
pull old RDS snapshot info and create csv files per region
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from asyncore import write | |
import boto3 | |
import datetime | |
import pytz | |
import csv | |
regions = ['us-east-1','eu-central-1','eu-west-1','ca-central-1','us-east-2','eu-west-2','us-west-1','ap-southeast-2','ap-southeast-1','us-west-2'] | |
headers = ['DBSnapshotIdentifier', 'DBInstanceIdentifier', 'SnapshotCreateTime', 'AllocatedStorage', 'DBSnapshotArn'] | |
now = pytz.utc.localize(datetime.datetime.now()) | |
for region in regions: | |
rds = boto3.client("rds", region) | |
with open(region + '_old_snapshots_2022.csv', 'w', encoding='UTF8') as f: | |
writer = csv.writer(f) | |
writer.writerow(headers) | |
for snapshot in rds.describe_db_snapshots()['DBSnapshots']: | |
# print(snapshot) | |
if snapshot['SnapshotCreateTime'] < now - datetime.timedelta(days=365): | |
row = [] | |
for item in headers: | |
row.append(snapshot[item]) | |
writer.writerow(row) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment