Last active
September 16, 2015 06:04
-
-
Save nurrony/cededadd12b8a0752a7e to your computer and use it in GitHub Desktop.
Restore all MongoDB collections from directory contains BSON files
This file contains hidden or 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/bin/env bash | |
| #Author nmrony<[email protected]> | |
| #you need to download it and give execution permission to run it | |
| #handle errors | |
| function die(){ | |
| echo $1; | |
| exit 1; | |
| } | |
| function importDB() { | |
| mongorestore -d $2 $1 2>/dev/null || die "Failed to open file"; | |
| } | |
| read -p "Enter database Name: " dbname; | |
| read -p "BSON directory path: " search_dir; | |
| filelist=$(ls "$search_dir"/*.bson 2>/dev/null); | |
| if [ -z "$filelist" ]; then | |
| die "Directory is empty or there is no bson file"; | |
| else | |
| importDB "$search_dir" "$dbname" | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment