This is probably insanely easy to do, but I can't find anything relevant to the topic. I'm setting up a custom logrotate.conf file for the logs in our service. As part of this, I would like to keep logs up to 7 days, compress antything older than 7 days, and delete anything older than 22 days. So far, I'm trying to test whether I can move compressed files to another directory, to keep the main log directory from becoming too cluttered.
My rules so far are as follows:
/home/user1/logs/profile_service/*.log
{
daily
rotate 7
copytruncate
compress
postrotate
mv /home/user1/logs/profile_service/*.gz /home/user1/logs/archive/profile_service/
endscript
}
My understanding of this is that the postrotate should move those .gz files into the archive directory. However, when I manually run logrotate:
logrotate -f /home/user1/logrotate.conf
It rotates the logs and appends the date to the files, but fails to compress the logs, and nothing gets into archive:
mv: cannot stat ‘/home/user1/logs/profile_service/*.gz’: No such file or directory
logrotate_script: line 2: compress: command not found
error: error running non-shared postrotate script for /home/user1/logs/profile_service/profile.log of '/home/user1/logs/profile_service/*.log
'
When I do not include the postrotate to move the files, the files are compressed normally.