mongodb- regular files by date of the backup to json

Database backup files
mongodump --host 172.17.0.7 --port 27018 --out /root/bak/
using backup files to restore to another library

/usr/local/mongodb-linux-x86_64-4.0.10/bin/mongorestore \
--db=test2 --host 172.17.0.7  \
--port 27018  \
/root/bak/test_mondb/call_record.bson

All fields to derive the timing json file corresponding to the library sorted by date

#!/bin/bash

if [ ! $1 ]; then
        echo " Example of use: $0 database_name [dir_to_store]"
        exit 1
fi
db=$1
out_dir=bak/`date +%Y_%m_%d`
#if [ ! $out_dir ]; then
#        out_dir="./"
#else
#        mkdir -p $out_dir
#fi
mkdir -p $out_dir

tmp_file="fadlfhsdofheinwvw.js"
echo "print('_ ' + db.getCollectionNames())" > $tmp_file
cols=`mongo $db --host 172.17.0.8 --port 27017  $tmp_file | grep '_' | awk '{print $2}' | tr ',' ' '`
for c in $cols
do
    mongoexport --host 172.17.0.8 --port 27017  -d $db -c $c -o "$out_dir/exp_${db}_${c}.json"
done
rm $tmp_file

Timed Run
0 0 1 * * /data/mongo-data/mongoexport.sh test_unicom_customer > /data/mongo-data/mongoexport.log 2>&1 &

Guess you like

Origin www.cnblogs.com/66li/p/12058769.html