Posts Tagged ‘db’

Post

Rotating MongoDB Log Files with Logrotate

In sysadmin on August 3, 2011 by Wenzi Tagged: , , , , ,

Rotating log files is something sys admins are all familiar with doing. There are a few ways to backup MongoDB, with the most common are the logRotate command and logrotate.

I prefer runCommand(“logRotate”) to rotate my log files. I administer a couple of MongoDB instalations and I check on them every day, and for those I prefer rotating them manually.

I do still have a mongoDB that is my little orphan server that runs logrotate. It just runs and I check on it every few weeks. For this one I use log rotate to make sure my disks do not fill up.

But theare are some people who prefer using logroatate, just because they are old school. I am one of those for everything but mongo.

So if you are used to logrotate, here is a script for you. You will have to change the parts for your own setup of course.

This server only ones one mongod ( yes, bad but this is not a critial machine ). If you are running more than one instnce the you will have to make changes obviously.

Place this in the file /etc/logrotate.d/mongodb

/var/log/mongodb/*.log {
	rotate 52
	size 50M
	compress
	weekly
	dateext
	missingok
	notifempty
	sharedscripts
	postrotate
		/bin/kill -SIGUSR1 `cat /var/lib/mongo/mongod.lock 2> /dev/null` 2> /dev/null || true
	endscript
}

Cheers

Comments Off