mongodb自动清log

vi /data/clear_mongolog.sh

#!/bin/bash
#Rotate the MongoDB logs to prevent a single logfile from consuming too much disk space.
#app=mongod
#mongodPath=/usr/local/mongo/bin
backpath=/data/backup/
echo  "rs.slaveOk();db.runCommand({logRotate:1});" >/tmp/logappend.js
chmod 755 /tmp/logappend.js
/usr/local/mongo/bin/mongo --port 27017 -u "root" -p "mypassword" --authenticationDatabase "admin"  admin /tmp/logappend.js
mv /data/mongodb/replset/mongod.log.20* $backpath
find $backpath -mtime +10 -name "mongod.log.20*" -exec rm -rf {} \;
#保留10天日志

crontab -e

   59 23 * * * root /data/clear_mongolog.sh

你可能感兴趣的:(mongodb)