Created
December 8, 2014 10:19
-
-
Save outbounder/831c91a328b3ac29b5e6 to your computer and use it in GitHub Desktop.
mongodb-sync.js
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
/** | |
* Usage: $ node mongodb-sync.js <user>@<ip> <database-name> | |
**/ | |
require("shelljs/global") | |
// prepare remote db | |
var remote_commands = [ | |
"mongodump --db "+process.argv[3]+" --out /tmp/mongodump-sync", | |
"tar -zcvf /tmp/mongodump-sync.tar.gz /tmp/mongodump-sync" | |
] | |
exec("ssh "+process.argv[2]+" '"+remote_commands.join(";")+"'") | |
// download locally and install | |
var local_commands = [ | |
"scp "+process.argv[2]+":/tmp/mongodump-sync.tar.gz /tmp/mongodump-sync.tar.gz", | |
"mkdir /tmp/mongodump-sync", | |
"tar -zxvf /tmp/mongodump-sync.tar.gz -C /tmp/mongodump-sync", | |
"rm /tmp/mongodump-sync/tmp/mongodump-sync/"+process.argv[3]+"/sessions.bson", | |
"mongorestore /tmp/mongodump-sync/tmp/mongodump-sync/"+process.argv[3], | |
"rm -rf /tmp/mongodump-sync*" | |
] | |
exec(local_commands.join(";")) | |
// erease leftovers after donwload | |
exec("ssh "+process.argv[2]+" 'rm -rf /tmp/mongodump-sync*'") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment