Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

logrotate entire directory containing log files

Is there a way using logrotate I can rotate entire directory and compress it instead of just the files in a particular directory? I tried experimenting using the config below but that does not work. Give the error message below:

Config:

/path/to/folder/test {
daily
rotate 5
missingok
compress
delaycompress
}

Error:

$logrotate -vf test.conf
reading config file test.conf
reading config info for /path/to/folder/test

Handling 1 logs

rotating pattern: /path/to/folder/test  forced from command line (5 
rotations)
empty log files are rotated, old logs are removed
error: error creating unique temp file: Permission denied
like image 662
iDev Avatar asked Nov 02 '17 01:11

iDev


People also ask

Where is the log rotation configuration for all log files located?

The main logrotate configuration file is located at /etc/logrotate. conf . The file contains the default parameters that logrotate uses when it rotates logs.

How do you force a log to rotate in the VAR log directory?

If you want to force Logrotate to rotate the log file when it otherwise would not have, use the --force flag: logrotate /home/sammy/logrotate. conf --state /home/sammy/logrotate-state --verbose --force.

What is Missingok in logrotate?

missingok : If the log file is missing, go on to the next one without issuing an error message. noolddir : Logs are rotated in the same directory the log normally resides in (this overrides the olddir option). daily : Log files are rotated every day.

What is Delaycompress in logrotate?

The delaycompress option makes the compression to delay till the next rotation of the log file. Delaycompress parameter would be useful for the application servers which requires writing to the logs continuously and delay compression for a particular amount of time.


1 Answers

Logrotate only operates upon individual files in directories, not the entire directory as a single entity. The most straight-forward solution would be a cronjob that calls something like gzip on that directory then moves/deletes files as you see fit.

like image 163
parttimeturtle Avatar answered Sep 20 '22 15:09

parttimeturtle