I would like to rotate my openvpn logs. How can I accomplish this?
I would like to rotate my openvpn logs. How can I accomplish this?
Add the contents of the following to new file /etc/rsyslog.d/20-ovpn.conf. This makes sure that log events sent to rsyslog are handled nicely.
# Create a template for the vpn log location
$template OpenVPN,"/var/log/openvpn/ovpn.log"
# Save log events where the programname starts with ovpn like ovpn-server to the
# location mentioned in the template
:programname, startswith, "ovpn-" -?OpenVPN
# Stop processing ovpn-* log events
:programname, startswith, "ovpn-" ~
Run this command and make sure that there is no output.
grep ^log /etc/openvpn/server.conf
If this command outputs any lines, then your need to go into the config and comment out the log or log-append line. This will trigger the default logging that sends it to syslog.
Finally, create a new file /etc/logrotate.d/ovpn and add the contents below to that file. This will do a weekly rotation or rotate once a log file becomes 100M in size. It will keep 4 weeks and compress everything but that last two.
/var/log/openvpn/*.log {
weekly
size 100M
rotate 4
compress
delaycompress
missingok
notifempty
create 640 syslog adm
}
Restart the rsyslog and then openvpn services to make sure these new configs take. You should see /var/log/openvpn and /var/log/openvpn/ovpn.log get created immediately by rsyslog after openvpn restarts.