Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace :heroku do
- HEROKU_APP_NAME = "YOUR_APP_NAME"
- LOCAL_DATABASE_NAME = "YOUR_LOCAL_DATABASE_NAME"
- desc "sync the local db with the db on heroku"
- task "sync_db" do
- puts "start"
- puts
- puts "Getting config information on heroku..."
- mongolab_uri_line = `heroku config --app #{HEROKU_APP_NAME} | grep MONGOLAB_URI`
- /mongodb:\/\/([^:]+):([^@]+)@([^\/]+)/ =~ mongolab_uri_line
- puts
- puts "host:#{$3}, database:#{$1}, user:#{$1}, password:#{$2}"
- puts
- unless File.exist?("db/heroku_sync_db")
- puts "mkdir db/heroku_sync_db"
- Dir::mkdir("db/heroku_sync_db")
- end
- puts
- puts "mongodump on heroku started..."
- `mongodump -h #{$3} -d #{$1} -u #{$1} -p #{$2} -o db/heroku_sync_db`
- puts "The dump file has been saved at db/heroku_sync_db ."
- puts "mongorestore on local started..."
- `mongorestore -d #{LOCAL_DATABASE_NAME} --drop db/heroku_sync_db/#{$1}`
- puts 'done.'
- end
- end
Add Comment
Please, Sign In to add comment