#!/bin/sh DATE=`date +%Y%m%d` DEL_DATE=$(date -d '-30 days' "+%Y%m%d") HOST=127.0.0.1:27017 USER=admin PASSWORD=123456 BACKUP_PATH="/backup/mongodbbackup/$DATE" date +%Y%m%d%H%M >>/data/log/mongodb_bak.log start() { cd /home/mongdb/ ./mongodump -h $HOST -u $USER -p $PASSWORD -o $BACKUP_PATH } execute() { start if [ $? -eq 0 ] then echo "mongodb back successfully!" >>/backup/mongodbbackup/log/mongodb_bak.log else echo "mongodb back fail!" >>/backup/mongodbbackup/log/mongodb_bak.log fi } execute rm -rf "/backup/mongodbbackup/${DEL_DATE}/"