Skip to content

Instantly share code, notes, and snippets.

@zweite
Created March 8, 2017 11:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zweite/cea659b3afa19fb11acef1463586a922 to your computer and use it in GitHub Desktop.
Save zweite/cea659b3afa19fb11acef1463586a922 to your computer and use it in GitHub Desktop.
backup mongo instance
#!/bin/bash
# $1 like 127.0.0.1:27029
mongoUrl=$1
querydb="echo 'show dbs;'| mongo "$mongoUrl" |awk '{if (NR>2 && NF==2){print \$1}}'"
dbs=`eval $querydb`
for db in $dbs; do
mongodump -h $mongoUrl -d $db -o ./
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment