數據庫備份爲文件
mongodump --host 172.17.0.7 --port 27018 --out /root/bak/
使用備份文件還原到另外一個庫linux
/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
定時導出對應庫中全部字段到json文件並按日期排序mongodb
#!/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
定時運行
0 0 1 * * /data/mongo-data/mongoexport.sh test_unicom_customer > /data/mongo-data/mongoexport.log 2>&1 &
數據庫