You are here
asterisk.logrotate
Put the following file at: /etc/logrotate.d/asterisk
Make sure it is owned by root with the same permissions and ownership as the other files in the logrotate.d directory.
/var/log/asterisk/messages {
missingok
rotate 5
weekly
create 0644 enswitch enswitch
postrotate
/usr/sbin/asterisk -rx 'logger reload' > /dev/null 2> /dev/null
endscript
}
/var/log/asterisk/full {
missingok
rotate 5
daily
create 0644 enswitch enswitch
postrotate
/usr/sbin/asterisk -rx 'logger reload' > /dev/null 2> /dev/null
endscript
}
/var/log/asterisk/cdr-csv/*csv {
missingok
rotate 5
monthly
create 0644 enswitch enswitch
}
# substitute "enswitch" with whatever user asterisk is running as
You can test it with the following command:
logrotate -vdf /etc/logrotate.d/asterisk
-v Turn on verbose mode.
-d Turns on debug mode and implies -v. In debug mode, no changes will be made to the logs or to the logrotate state file.
-f, --force
Tells logrotate to force the rotation, even if it doesn't think this is necessary. Sometimes this is useful after adding new entries to
logrotate, or if old log files have been removed by hand, as the new files will be created, and logging will continue correctly.
You can run it immediately with the force option:
logrotate -vf /etc/logrotate.d/asterisk
Logrotate Notes (taken from man logrotate):
# Don't complain if the file is missing
missingok
# Keep 5 rotations
rotate 5
# Rotate weekly
# Daily would be "daily"
weekly
# Make it readable by everybody (-rw-r--r--) and owned by enswitch
create 0644 enswitch enswitch
# Next three lines run a script to restart asterisk
# The middle line instructs asterisk to reload it's logger module
# it is needed so that asterisk will write to the new file.
postrotate
/usr/sbin/asterisk -rx 'logger reload' > /dev/null 2> /dev/null
endscript
Last, the following option as described in the manpage could be useful if you are backing up the cdrs. It would create a unique filename of the old data:
dateext
Archive old versions of log files adding a daily extension like YYYYMMDD instead of simply adding a number.
Shamelessly take from: http://www.voip-info.org
- shanondink's blog
- Log in or register to post comments