Guest User

Untitled

a guest
Oct 17th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. namespace :heroku do
  2. HEROKU_APP_NAME = "YOUR_APP_NAME"
  3. LOCAL_DATABASE_NAME = "YOUR_LOCAL_DATABASE_NAME"
  4.  
  5. desc "sync the local db with the db on heroku"
  6. task "sync_db" do
  7. puts "start"
  8. puts
  9. puts "Getting config information on heroku..."
  10. mongolab_uri_line = `heroku config --app #{HEROKU_APP_NAME} | grep MONGOLAB_URI`
  11. /mongodb:\/\/([^:]+):([^@]+)@([^\/]+)/ =~ mongolab_uri_line
  12. puts
  13. puts "host:#{$3}, database:#{$1}, user:#{$1}, password:#{$2}"
  14. puts
  15. unless File.exist?("db/heroku_sync_db")
  16. puts "mkdir db/heroku_sync_db"
  17. Dir::mkdir("db/heroku_sync_db")
  18. end
  19. puts
  20. puts "mongodump on heroku started..."
  21. `mongodump -h #{$3} -d #{$1} -u #{$1} -p #{$2} -o db/heroku_sync_db`
  22. puts "The dump file has been saved at db/heroku_sync_db ."
  23.  
  24. puts "mongorestore on local started..."
  25. `mongorestore -d #{LOCAL_DATABASE_NAME} --drop db/heroku_sync_db/#{$1}`
  26.  
  27. puts 'done.'
  28.  
  29. end
  30. end
Add Comment
Please, Sign In to add comment