Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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