数据库
首页 > 数据库> > MongoDB 服务器日志清理脚本说明

MongoDB 服务器日志清理脚本说明

作者:互联网

清理脚本:/root/scripts/clean_mongodb_log.sh

#!/bin/bash
#
set -u

echo "=== Started Time: `date` ==="

mongodb_logdir=/var/log/mongodb
days=7

pid=$(pidof $(which mongod))

if [ "X${pid}" != "X" ];then
  kill -SIGUSR1 $pid
  sleep 1m
  find $mongodb_logdir/ -type f | grep -v -x -f pattern.txt | xargs gzip
  find $mongodb_logdir/ -type f -mtime +$days -delete
  echo "clean mongodb log success!"
else
  echo "clean mongodb log failure!"
fi

echo "=== Finished Time: `date` ==="

# end

pattern.txt文件内容:

.*mongod.log$
.*gz$

定时清理任务:

00 00 * * * cd /root/scripts;./clean_mongodb_log.sh >/var/log/clean_mongodb.log 2>&1

标签:log,mongodb,pid,echo,logdir,clean,MongoDB,服务器,日志
来源: https://www.cnblogs.com/varden/p/15342991.html