Description
Operating system: CentOS
MongoDB installation directory:/usr/local/mongodb
MongoDB Database storage directory:/home/data/mongodb/mongodb_data
MongoDB Log storage directory:/home/data/mongodb/mongodb_log
Purpose of implementation:
Save to the MongoDB database log on a daily basis and keep only the last 7 days of log records.
Specific operation:
Use commands from the MongoDB database to cut logs
Ps-def | grep Mongod
KILL-SIGUSR1 <mongod Process id>
1. Create MongoDB database log Cut script
vi/home/crontab/cut_mongodb_log.sh #编辑
#!/bin/sh
Datafile=/home/data/mongodb/mongodb_data #Mongodb数据库存放目录
Logfile=/home/data/mongodb/mongodb_log #Mongodb日志存放目录
Days=7 #代表删除7天前的备份, which is to keep only the last 7 days of backup
/BIN/KILL-SIGUSR1 ' cat $datafile/mongod.lock ' #切割日志
Find $logfile/-mtime + $days-delete #删除7天前的备份文件
: wq! #保存退出
2, add task plan, modify/etc/crontab
Vi/etc/crontab #在最后一行添加
0 0 * * */home/crontab/cut_mongodb_log.sh #表示每天凌晨执行备份
: wq! #保存退出
3. Restart the Crond to make the settings effective
/etc/rc.d/init.d/crond Restart #yum install-y Vixie-cron Installation Scheduled tasks may not be preinstalled on some systems
Chkconfig Crond on #设为开机启动
Service Crond start #启动
Log records similar to MONGODB.LOG.2015-02-28T06-33-20 are generated daily in the/home/data/mongodb/mongodb_log directory
And keep only the last 7 days of logging.
At this point, Linux is timed to cut the MongoDB database log and delete the log records before the specified number of days is complete.
This article is from the "Intelligent Future _XFICC" blog, please be sure to keep this source http://xficc.blog.51cto.com/1189288/1633379
Regularly cut MongoDB database logs under Linux and delete log records before the specified number of days