Created
June 7, 2016 12:09
-
-
Save Navinnair/50b68f7664de579f0b4c74452661ab23 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'yaml' | |
dbconfig = YAML::load(File.open('config/database.yml')) | |
tables_to_export = %w[ users students ] | |
destination_folder = 'tmp' | |
db_conf = 'config/database.yml' | |
db = YAML::load(File.open( db_conf ))["production"] | |
tables_to_export.each do |table| | |
dest_file = File.join( destination_folder, "#{table}.csv" ) | |
command_dump = "mysql -B -u#{db["username"]} -p#{db["password"]} #{db["database"]} -e 'SELECT * FROM #{table};' > #{dest_file}" | |
puts "CSV exporting #{table} to #{dest_file}" | |
system( command_dump ) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment