Last active
December 28, 2015 13:39
-
-
Save GusGA/7509775 to your computer and use it in GitHub Desktop.
Rake task to restore mongo databases, in both ways Prod to Local and Local to Prod
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
namespace :prod do | |
desc "Copy local database to production" | |
task :sync => :environment do | |
system 'mongodump -h localhost:27017 -d <LOCAL_DB_NAME> -o /path/to/folder' | |
system 'mongorestore -h host:port -db <PROD_DB_NAME> -u <DB_USER> -p <DB_PASS> --drop /path/to/folder/local_db_name' | |
end | |
end |
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
namespace :localdb do | |
desc "Copy production database to local" | |
task :sync => :environment do | |
system 'mongodump -h host:port -d PROD_DB_NAME -u <DB_USER> -p <DB_PASS> -o db/backups/' | |
system 'mongorestore -h localhost --drop -d DEV_DATABASE_NAME db/backups/PROD_DB_NAME/' | |
end | |
end |
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
namespace :prodheroku do | |
desc "Copy production database to local" | |
task :sync => :environment do | |
system 'mongodump -h host:port -d YOUR_HEROKU_APP_NAME -u heroku -p HEROKU_PASSWORD -o db/backups/' | |
system 'mongorestore -h localhost --drop -d DEV_DATABASE_NAME db/backups/YOUR_HEROKU_APP_NAME/' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment