Expire records from the dba log automatically?

Post Reply
kgc
OpenVpn Newbie
Posts: 4
Joined: Mon Jul 13, 2015 6:40 pm

Expire records from the dba log automatically?

Post by kgc » Sat Feb 06, 2016 1:03 am

By policy we do not maintain logs older than 2 weeks. Can anyone share an example of how to expire records from the dba by age? (Or at all?)

Thanks!

kgc
OpenVpn Newbie
Posts: 4
Joined: Mon Jul 13, 2015 6:40 pm

Re: Expire records from the dba log automatically?

Post by kgc » Wed Feb 10, 2016 11:31 pm

Should anyone else want to do it, this should work provided you have a gnu-ish date.

Code: Select all

#!/bin/bash

DATE=`date --date "-14 days" +%s`;

/usr/local/openvpn_as/bin/sqlite3 /usr/local/openvpn_as/etc/db/log.db "delete from log where timestamp < $DATE"

oibaf
OpenVpn Newbie
Posts: 6
Joined: Fri Aug 14, 2015 4:20 pm

Re: Expire records from the dba log automatically?

Post by oibaf » Sun Jan 03, 2021 3:06 pm

2021 update :):
  • use system sqlite3 (no longer included in openvpn-as package, at least on Debian);
  • do a VACUMM to free DB space (otherwise no file size reduction).

Code: Select all

#!/bin/bash

DATE=`date --date "-14 days" +%s`;

/usr/bin/sqlite3 /usr/local/openvpn_as/etc/db/log.db "delete from log where timestamp < $DATE"
/usr/bin/sqlite3 /usr/local/openvpn_as/etc/db/log.db "VACUUM"

Post Reply