Last active
August 20, 2017 04:51
-
-
Save shivabhusal/38f3a43e73c59160594e87b04d0d8cc7 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 'date' | |
Tables = [ | |
"admin_users", | |
"active_admin_comments", | |
"arx_location", | |
"arx_user", | |
"arx_location_owner", | |
"arx_machine", | |
"ar_internal_metadata", | |
"arx_exercise_set", | |
"arx_oauth2_access_token", | |
"arx_oauth2_arx_code", | |
"arx_oauth2_auth_code", | |
"arx_oauth2_client", | |
"arx_oauth2_refresh_token", | |
"arx_pastdatauser", | |
"arx_range_of_motion", | |
"migration_versions", | |
"profiles", | |
"schema_migrations" | |
] | |
config_content = File.read File.expand_path('../../../config/database.yml', __FILE__) | |
erb_parsed = ERB.new(config_content).result | |
db_config = YAML.load(erb_parsed) | |
namespace :db do | |
task :import do | |
prod_server = db_config['production']['host'] | |
prod_username = db_config['production']['username'] | |
prod_password = db_config['production']['password'] | |
prod_db = db_config['production']['database'] | |
local_server = db_config['development']['host'] | |
local_username = db_config['development']['username'] | |
local_password = db_config['development']['password'] | |
local_db = db_config['development']['database'] | |
`mkdir ~/db_dumps` | |
Tables.each do |table_name| | |
puts '~' * 100 | |
dump_path = File.expand_path "~/#{table_name}.#{DateTime.now.to_s}.csv" | |
puts "Exporting from table '#{table_name}'" | |
puts `bcp #{table_name} out #{dump_path} -S #{prod_server} -U #{prod_username} -P '#{prod_password}' -d #{prod_db} -c -t ','` | |
puts "Importing to table '#{table_name}'" | |
puts `bcp #{table_name} in #{dump_path} -S #{local_server} -U #{local_username} -P '#{local_password}' -d #{local_db} -c -t ',' -q` | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment