Created
July 28, 2014 07:35
-
-
Save jcppman/bca37e081664c7b51c3d to your computer and use it in GitHub Desktop.
copyMongo
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
#!/usr/local/bin/fish | |
function tips | |
set_color red | |
echo $argv[1] | |
set_color normal | |
end | |
set SOURCE $argv[1] | |
set TARGET $argv[2] | |
set DBNAME $argv[3] | |
# Drop target Db | |
tips "Drop Database $TARGET/$DBNAME" | |
set RESULT (mongo $TARGET/$DBNAME --eval "db.dropDatabase()") | |
# Get all collection | |
set COLLECTIONS (mongo $SOURCE/$DBNAME --quiet --eval "print(db.getCollectionNames().join('\n'))") | |
# Export & Import | |
for COLLECTION in $COLLECTIONS | |
tips "Copy Mongo Collection '$COLLECTION' from $SOURCE to $TARGET" | |
mongoexport -h $SOURCE -d $DBNAME -c $COLLECTION | mongoimport -h $TARGET -d $DBNAME -c $COLLECTION | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment