Skip to content

Instantly share code, notes, and snippets.

@liamdawson
Created July 27, 2021 02:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liamdawson/9b5e0d0d961387855ab075ba29237d1e to your computer and use it in GitHub Desktop.
Save liamdawson/9b5e0d0d961387855ab075ba29237d1e to your computer and use it in GitHub Desktop.
Extract a CSV of manual RDS DB snapshots in an AWS account
# frozen_string_literal: true
source "https://rubygems.org"
gem "aws-sdk-rds"
#!/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