Sha256: 06d4ca6dc992db450ebd4bd180d1be35384a32318c2c234f498c3a4fc654169b
Contents?: true
Size: 1.7 KB
Versions: 1
Compression:
Stored size: 1.7 KB
Contents
#!/usr/bin/env ruby require_relative '../lib/rds_rotate_db_snapshots' rrds = RdsRotateDbSnapshots.new(script_name: File.basename($PROGRAM_NAME), cli: true) if rrds.options[:aws_access_key].nil? || rrds.options[:aws_secret_access_key].nil? puts "You must specify your Amazon credentials via --aws-access-key and --aws-secret_access-key and " \ "--aws-session-token" exit 1 end if rrds.options[:aws_region].nil? puts "You must specify your AWS Region via --aws-region" exit 1 end if ARGV.empty? && rrds.options[:by_tags].nil? puts "You must provide at least one DB Indentifier when not rotating by tags" exit 1 end if rrds.options[:by_tags].nil? db_indentifier_ids = ARGV db_indentifier_ids.each do |db_id| next unless db_id.nil? || db_id.gsub(/\s/, '').empty? # sanity check puts "Invalid db indentifier: #{db_id}" exit 1 end else puts "Ignoring supplied db_indentifier_ids because we're rotating by tags." unless ARGV.empty? if rrds.options[:by_tags].empty? puts "Rotating by tags but no tags specified? Refusing to rotate all snapshots!" exit 1 end end if rrds.options[:backoff_limit].negative? puts "A negative backoff limit doesn't make much sense." exit 1 end rrds.create_snapshot(rrds.options[:create_snapshot], db_indentifier_ids) if rrds.options[:create_snapshot] all_snapshots = [] if rrds.options[:by_tags] rrds.rotate_by_tags else snapshots = rrds.get_db_snapshots(snapshot_type: 'manual').delete_if { |e| e[:status] != 'available' } db_indentifier_ids.each do |db_id| rrds.rotate_em( snapshots.select { |ss| ss[:db_instance_identifier] == db_id } .sort { |a, b| a[:snapshot_create_time] <=> b[:snapshot_create_time] } ) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rds-rotate-db-snapshots-0.5.2 | bin/rds-rotate-db-snapshots |