I want logrotate
to copy and truncate log file and use olddir on different physical disk. According to manual, olddir can't be on different physical disk because default behaviour of logrotate is to only rename original log file, which wouldn't be possible with different physical disk.
Well, but I am using copytruncate
directive, which makes a copy of original file and then truncates original file. So there shouldn't be problem with moving newly copied file to different location on different physical disk.
But when I run logrotate, it still complains about logfile and olddir beeing on different devices.
Is there any way around it ? Possibly running some custom postrotate script which would move log files to desired location ?
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.
olddir directory Logs are moved into directory for rotation. The directory must be on the same physical device as the log file being rotated, unless copy, copytruncate or renamecopy option is used. The directory is assumed to be relative to the directory holding the log file unless an absolute path name is specified.
Rotating log files is important for several reasons. First, you probably don't want older log files eating up too much of your disk space. Second, when you need to analyze log data, you probably don't want those log files to be extremely large and cumbersome.
If you want to rotate /var/log/syslog it needs to be listed in a logrotate config file somewhere, and you just run logrotate . If it rotated recently, then logrotate -f to force it to do it again. So, you need that in a file, normally either /etc/logrotate. conf or as a file snippet in /etc/logrotate.
This is from logrotate man page.
olddir directory <br>
Logs are moved into directory for rotation. **The directory must be on the
same physical device as the log file being rotated**, and is assumed to be
relative to the directory holding the log file unless an absolute path
name is specified. When this option is used all old versions of the log
end up in directory. This option may be overridden by the noolddir
option.
Existence of olddir
on same physical device is limitation.
One can use below workaround.
set olddir
to directory in same physical disk, and use postrotate
script to move contents of olddir
to directory on different physical device.
Example logrotate configuration file:
/var/log/httpd/*log {
copytruncate
olddir /var/log/httpd/olddir
rotate 5
missingok
notifempty
sharedscripts
delaycompress
postrotate
mv /var/log/httpd/olddir/* /vagrant/httpd/olddir/
/sbin/service httpd reload > /dev/null 2>/dev/null || true
endscript
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With