Regularly cut MongoDB database logs under Linux and delete log records before the specified number of days (RPM)

Source: Internet
Author: User
Tags create mongodb

Article turned from: http://www.osyunwei.com/archives/8998.html

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! #保存退出

System operation and maintenance www.osyunwei.com warm reminder: qihang01 original Content © Copyright, reproduced please indicate the source and the original link

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.

To cut the MongoDB database log regularly and delete the log records before the specified number of days (go)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.