Log file rotation
Edit: this is significantly changed to account for the crontab file being re-created at every boot!
If you have installed the optional logrotate command as per my first post then this is where we configure it. For an explanation of how it works please refer to @S0litiare’s excellent post and the link at the end. Bear in mind that the file locations on QNAPs are different, due to the root file system being re-created at boot.
Create this file
nano /opt/etc/logrotate.d/storj1
This is what I put into my file:
/share/CACHEDEV1_DATA/sn/sn1/storj.log {
rotate 30
daily
dateext
copytruncate
missingok
notifempty
}
This will rotate the file daily, use a date stamp for the file names and keep 30 files. Obviously, if you want other values then modify this to your taste.
Next, we need to make this command run once a day (in my case). I have decided on 3 AM.
(Note for Linux experts: you can NOT use crontab -e on QNAP, nor can you edit the crontab file.)
Create a script in the Entware startup dir:
nano /opt/etc/init.d/S89cronjobadd.sh
Paste this into the file and save:
#!/bin/bash
echo '0 3 * * * /opt/sbin/logrotate /opt/etc/logrotate.conf' >> /etc/config/crontab
crontab /etc/config/crontab
/etc/init.d/crond.sh restart
The script adds the line to start logrotate to the end of the crontab file and restarts the daemon.
Make the script executable and run it:
chmod u+x /opt/etc/init.d/S89cronjobadd.sh
/opt/etc/init.d/S89cronjobadd.sh
Check that it worked:
`crontab -l’
The last line must be the logrotate line you added.