Created
August 28, 2014 09:27
-
-
Save danmaispace/f42d9ef2747ef520e157 to your computer and use it in GitHub Desktop.
export mongo all connections with last 100 documents
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
#!/bin/bash | |
# 2 parameters (database name, dir to store files). | |
# http://docs.mongodb.org/manual/reference/program/mongoexport/ | |
# example: ./mongoexport_limit.sh database /data/dump/ 100 username password | |
if [ ! $1 ]; then | |
echo " Example of use: $0 database_name [dir_to_store]" | |
exit 1 | |
fi | |
db=$1 | |
out_dir=$2 | |
limit=$3 | |
username=$4 | |
password=$5 | |
if [ ! $out_dir ]; then | |
out_dir="./" | |
else | |
mkdir -p $out_dir | |
fi | |
tmp_file="fadlfhsdofheinwvw.js" | |
echo "print('_ ' + db.getCollectionNames())" > $tmp_file | |
cols=`/home/jesse/sources/mongodb-linux-x86_64-2.6.4/bin/mongo --host localhost $db --username $username --password $password $tmp_file | grep '_' | awk '{print $2}' | tr ',' ' '` | |
for c in $cols | |
do | |
echo "/home/jesse/sources/mongodb-linux-x86_64-2.6.4/bin/mongoexport --host localhost -d $db --username $username --password $password -c $c --sort '{_id: -1}' --limit $limit -o $out_dir/exp_${db}_${c}.json" | |
/home/jesse/sources/mongodb-linux-x86_64-2.6.4/bin/mongoexport --host localhost -d $db --username $username --password $password -c $c --sort '{_id: -1}' --limit $limit -o "$out_dir/exp_${db}_${c}.json" | |
done | |
rm $tmp_file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment