Hello,
The Issue:
We ran into an issue where we had to review Asterisk logs from two days ago. But the Asterisk logs were gone. The only Asterisk log, was the full
from the current day.
After reviewing the contabs, we see the following:
Problematic Script 1
Under /etc/cron.daily/vpbx_clean_old_logs
we see that there is the following:
path="/var/log/vitalpbx/"
find $path -name "log_*.log" -type f -mtime +7 | xargs rm >/dev/null 2>&1
/usr/share/vitalpbx/scripts/clean_logs >/dev/null 2>&
First, as far as I am aware there are no files named log_
, there are _log
, for example, queue_log.log
. So the first line seems like it is useless.
Then, it calls the clean_logs
script. That script, among other files that it deletes, it does the below:
rm -f /var/log/asterisk/full.*
rm -f /var/log/asterisk/full-*
Meaning, this will delete any Asterisk full log file that is older than today.
Problematic Script 2
Additionally, under /etc/cron.d/vpbx
there is the following rule:
0 0 */2 * * root /usr/share/vitalpbx/scripts/clean_server >/dev/null 2>&1
This script, runs on every second day of the month. Among other stuff, that script does the below
rm -f /var/log/asterisk/full.*
rm -f /var/log/asterisk/full-*
Meaning, every second day, if the above script didn’t nuke the Asterisk logs, this one will.
Solution:
What did, is we stopped both of these scripts and modified /etc/logrotate.d/asterisk-pbx
to look like this:
var/log/asterisk/messages
/var/log/asterisk/event_log
/var/log/asterisk/full
/var/log/asterisk/dtmf
/var/log/asterisk/fail2ban {
daily
dateext
dateformat -%Y%m%d
rotate 7
missingok
notifempty
sharedscripts
create 0640 asterisk asterisk
su asterisk asterisk
postrotate
/usr/sbin/asterisk -rx 'logger reload' > /dev/null 2> /dev/null
endscript
}
Now, after more than a week being like this, we see that it works fine:
root@core1:~# ls -la /var/log/asterisk/ | grep full
-rw-r----- 1 asterisk asterisk 12283171 Jul 23 11:42 full
-rw-r----- 1 asterisk asterisk 41153722 Jul 17 00:00 full-20240717
-rw-r----- 1 asterisk asterisk 38352665 Jul 18 00:00 full-20240718
-rw-r----- 1 asterisk asterisk 32241982 Jul 19 00:00 full-20240719
-rw-r----- 1 asterisk asterisk 32663989 Jul 20 00:00 full-20240720
-rw-r----- 1 asterisk asterisk 3597405 Jul 21 00:00 full-20240721
-rw-r----- 1 asterisk asterisk 23478627 Jul 22 00:00 full-20240722
-rw-r----- 1 asterisk asterisk 49269564 Jul 23 00:00 full-20240723
With that being said, you can likely set dateext
and dateformat -%Y%m%d
under /etc/logrotate.conf
Suggestion:
To fix this problem, we suggest doing the following:
- Use log rotate to rotate and delete files. Of course, with the correct config.
- Use a single script that runs nightly to cleans up anything that log rotate missed. For example, there may be
full.1
orqueue_log.2
that log rotate could not delete. Or for examplefull
files older than 8 days andqueue_log
files older than 30 days.
Thank you