Skip to content

Instantly share code, notes, and snippets.

@pagebrooks
Last active December 3, 2019 11:54
Show Gist options
  • Save pagebrooks/6390198 to your computer and use it in GitHub Desktop.
Save pagebrooks/6390198 to your computer and use it in GitHub Desktop.

Procedure for Mongodb Logrotate

The default install for Mongodb does not configure log rotation.

In /etc/logrotate.d/mongod

/var/log/mongodb/*.log {
    daily
    rotate 30
    compress
    dateext
    missingok
    notifempty
    sharedscripts
    postrotate
        /bin/kill -SIGUSR1 `cat /media/data/mongodb/mongod.lock 2> /dev/null` 2> /dev/null || true
    endscript
  • Rotate logs daily
  • Delete log files older than 30 days
  • Compress the log files
  • Use YYYYMMDD for the archive extension
  • Don't fail if there is no log file
  • Don't archive empty log files
  • Only run postrotate script once, even if multiple files are present
  • Signal to Mongo that we are writing to a new log file. Apparently, mongo will continue to write to the old log file if you do not signal. The cat command is used to obtain the PID for the mongod process.

Resources

http://stackoverflow.com/questions/5004626/mongodb-log-file-growth http://docs.mongodb.org/manual/tutorial/rotate-log-files/

@pballester
Copy link

Did you miss to close the bracket on the script?

@felvis
Copy link

felvis commented Mar 12, 2018

btw - yes )

@jeeva-spec
Copy link

jeeva-spec commented Aug 10, 2019

above one is zipped current log file with a current date but no new log file created.i've restarted the process to create a log file again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment