一个mongodb的备份脚本

把如下脚本放到计划任务里根据自己的需要进行。

#! /bin/bash

cd /scripts/backupMongoDB/
exec < ip.list   ##############ip.list 例子:test 192.168.1.10
while read line
do
    a=echo $line | awk '{print $1}'
    b=echo $line | awk '{print $2}'

 
mkdir -p /data/backup/mongoDB/$a/$(date +%Y%m%d)/
    echo "-----------------------------------" >> info
    echo "$(date +%Y%m%d%H%M) $a Backup Start ..." >> info
    /data/tools/mongodb/bin/mongodump -h "$a/$b:27017" --oplog --gzip -o /data/backup/mongoDB/$a/$(date +%Y%m%d)/
    if [ $? == 0 ];then
        echo "$(date +%Y%m%d%H%M) $a Backup Successful!" >> info
        echo "" >> info
    else
        echo "$(date +%Y%m%d%H%M) $a Backup Failed!!!!!!!!!!" >> info
        echo "" >> info
    fi


    echo "$(date +%Y%m%d%H%M) oplog Backup Start ..." >> info
    /data/tools/mongodb/bin/mongodump -h "$a/$b:27017" -d local -c oplog.rs --gzip -o /data/backup/mongoDB/$a/$(date +%Y%m%d)/
    if [ $? == 0 ];then
        echo "$(date +%Y%m%d%H%M) oplog Backup Successful!" >> info
        echo "" >> info
        echo "" >> info
    else
        echo "$(date +%Y%m%d%H%M) oplog Backup Failed!!!!!!!!!!" >> info
        echo "" >> info
        echo "" >> info
    fi
done
python /scripts/backupMongoDB/MyEmail/pyemail.py ###这里写一个发邮件的py脚本,也可是直接用shell表示(mail -s "mongo备份完成"[email protected]
echo > info

你可能感兴趣的:(linux,常见问题,数据库)