Created
July 27, 2021 02:09
-
-
Save liamdawson/9b5e0d0d961387855ab075ba29237d1e to your computer and use it in GitHub Desktop.
Extract a CSV of manual RDS DB snapshots in an AWS account
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
# frozen_string_literal: true | |
source "https://rubygems.org" | |
gem "aws-sdk-rds" |
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
#!/usr/bin/env ruby | |
# frozen_string_literal: true | |
require "aws-sdk-rds" | |
require "csv" | |
require "time" | |
CSV_HEADERS = [ | |
"region", | |
"db_instance", | |
"snapshot_id", | |
"status", | |
"snapshot_created_at", | |
"storage_type", | |
"allocated_storage", | |
] | |
if ARGV.empty? | |
puts "expected a list of regions" | |
exit(1) | |
end | |
regions = ARGV | |
def for_region(region) | |
client = Aws::RDS::Client.new(region: region) | |
rows = [] | |
client.describe_db_snapshots( | |
include_public: false, | |
snapshot_type: "manual", | |
include_shared: true, | |
).each do |response| | |
response.db_snapshots.each do |snapshot| | |
rows << [ | |
region, | |
snapshot.db_instance_identifier, | |
snapshot.db_snapshot_identifier, | |
snapshot.status, | |
snapshot.snapshot_create_time.iso8601, | |
snapshot.storage_type, | |
snapshot.allocated_storage, | |
] | |
end | |
end | |
rows | |
end | |
CSV.open("snapshots.csv", "w") do |csv| | |
csv << CSV_HEADERS | |
regions.each do |region| | |
for_region(region).each { |row| csv << row } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment