lib/preserve-rds-snapshot/cli.rb in preserve-rds-snapshot-0.3.0 vs lib/preserve-rds-snapshot/cli.rb in preserve-rds-snapshot-0.3.1

- old
+ new

@@ -32,10 +32,11 @@ resp.db_snapshots.each do |s| puts "#{s.db_snapshot_identifier}\t#{s.snapshot_create_time}" end rescue ::Aws::Errors::ServiceError => e $stderr.puts e + exit 1 end end desc :init, "initialize instance" option :generations, @@ -55,10 +56,11 @@ end end fix_tags rescue ::Aws::Errors::ServiceError => e $stderr.puts e + exit 1 end end desc :preserve, 'copy automated snapshot to manual' def preserve @@ -88,10 +90,11 @@ puts "delete#{dry_run_msg}\t#{expired.db_snapshot_identifier}" end end rescue ::Aws::Errors::ServiceError => e $stderr.puts e + exit 1 end end desc :copy, 'copy snapshot' option :source_db_snapshot_identifier, @@ -119,10 +122,11 @@ ) s = resp.db_snapshot puts "#{s.db_snapshot_identifier}\t#{s.snapshot_create_time}" rescue ::Aws::Errors::ServiceError => e $stderr.puts e + exit 1 end end desc :latest, 'show latest snapshot' def latest @@ -143,10 +147,11 @@ db_instance_identifier: db_instance_identifier ) latest = resp.db_snapshots.sort_by(&:snapshot_create_time).last rescue ::Aws::Errors::ServiceError => e $stderr.puts e + exit 1 end latest end def db_instances(db_instance_identifier = nil) @@ -159,10 +164,11 @@ list << i if preserve_tag(i.db_instance_identifier, 'db') end end rescue ::Aws::Errors::ServiceError => e $stderr.puts e + exit 1 end list end def preserve_snapshot_name(db_snapshot_identifier) @@ -175,10 +181,11 @@ else begin return ec2.security_groups(group_names: ['default']).first.owner_id rescue ::Aws::Errors::ServiceError => e $stderr.puts e + exit 1 end end end def rds_arn(resource_id, type) @@ -192,10 +199,11 @@ resource_name: rds_arn(resource_id, type) ) tag = resp.tag_list.find {|t| t[:key] == PRESERVE_TAG_NAME} rescue ::Aws::Errors::ServiceError => e $stderr.puts e + exit 1 end tag end def enable_preserve(resource_id, generations) @@ -209,10 +217,11 @@ ) return resp.successful? end rescue ::Aws::Errors::ServiceError => e $stderr.puts e + exit 1 end end # fix v0.2.0 format tag to latest def fix_tags @@ -236,10 +245,11 @@ ) end end rescue ::Aws::Errors::ServiceError => e $stderr.puts e + exit 1 end end def copy_snapshot(db_snapshot_identifier) begin @@ -249,10 +259,11 @@ tags: [key: PRESERVE_TAG_NAME, value: 'true'] ) return resp.db_snapshot rescue ::Aws::Errors::ServiceError => e $stderr.puts e + exit 1 end end def expired_snapshots(db_instance_identifier, generations) expired_snapshots = [] @@ -265,9 +276,10 @@ preserve_tag(s.db_snapshot_identifier, 'snapshot') }.sort_by(&:snapshot_create_time).reverse expired_snapshots = snapshots[generations..-1] if snapshots.size > generations rescue ::Aws::Errors::ServiceError => e $stderr.puts e + exit 1 end expired_snapshots end end end