Log Rotation in windows

I need to set mongodb. log rotation and to keep files for sometime in windows. I was adding logRotate:rename in conf file file. But it’s not working

Hello, welcome to the MongoDB community.

You can do it as follows.

mongod.conf

systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log
  logRotate: reopen
processManagement:
  pidFilePath: /var/run/mongodb/mongod.pid

Use the Linux utility logrotation to create an automation
Create this file /etc/logrotate.d/mongod.conf

/var/log/mongodb/mongod.log {
  daily
  size 100M
  rotate 10
  missingok
  compress
  delaycompress
  notifempty
  create 640 mongod mongod
  sharedscripts
  postrotate
    /bin/kill -SIGUSR1 `cat /var/run/mongodb/mongod.pid 2>/dev/null` >/dev/null 2>&1
  endscript
}

Read the options to adjust as needed.

To test the functionality use
logrotate -f /etc/logrotate.d/mongod

Here is a link that can serve as a basis:

I need to set up in windows environment not in Linux/Unix. Is it possible to set it up like up this. While using logRotate, I was getting error. So could you please confirm

Sorry, I now understand that it is a Windows environment. Can you tell me what error is occurring and how the mongod.conf file is configured?

Furthermore, the error is to raise the service or perform the rotation on the mongodb.

Actually I want to know in windows how to make log rotation possible in mongodb without mongodb restart. Once I made logAppend:false in mongod.cfg and restartedmongodb from service, it will be creating new file. But I want to implement it automatically without mongodb restart.

Could you please help me in this whether I can do it automatically by making updation in cfg file.

You can try using LogRotateWin to automate the procedure.

It works basically the same as Linux, read the document and see if it helps =D

https://sourceforge.net/p/logrotatewin/wiki/LogRotate/

Hi @JINSU_MANI,
You can create a custom role for the log rotation and schedule the run of the following command:

db.adminCommand( { logRotate : “server” } )

Regards

1 Like