Using file of system logrotate for compression mongodb log files

Just insert next code to the /etc/logrotate.d/mongodb:

   /var/log/mongodb/mongodb.log {
           size 10M 
           missingok
           rotate 14
           compress
           notifempty
           mail root@localhost
           create 0640 mongodb nogroup
           postrotate
             killall --signal USR1 mongod
             find /var/log/mongodb -type f -regex '.*/mongodb\.log\.[-0-9]+T[-0-9]+$' -exec rm {} \;
           endscript
  }       
Scroll to top