Skip to content

Instantly share code, notes, and snippets.

@hSATAC
Created July 11, 2016 03:05
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 hSATAC/a4147b15365d661ed735473dcb74839e to your computer and use it in GitHub Desktop.
Save hSATAC/a4147b15365d661ed735473dcb74839e to your computer and use it in GitHub Desktop.
Download RDS log
#!/usr/bin/env ruby
require 'rubygems'
require 'aws-sdk-core'
require 'pp'
Aws.config.update({
:access_key_id => ENV["AWS_ACCESS_KEY"],
:secret_access_key => ENV["AWS_SECRET_KEY"],
:region => 'ap-northeast-1'
})
rds = Aws::RDS::Client.new
db_instance_identifier = 'myrds'
abort("Enter log filename.") if ARGV[0].nil?
rds_log_file = ARGV[0]
out_log_file = ARGV[0]
opts = {
db_instance_identifier: db_instance_identifier,
log_file_name: rds_log_file,
number_of_lines: 100000000,
marker: "0"
}
additional_data_pending = true
File.open(out_log_file, "wb+") do |file|
while additional_data_pending do
out = rds.download_db_log_file_portion(opts)
puts out[:additional_data_pending]
file.write(out[:log_file_data])
additional_data_pending = (opts[:marker] != out[:marker])
puts out[:marker]
opts[:marker] = out[:marker]
# additional_data_pending is not stable.
#additional_data_pending = out[:additional_data_pending]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment