fail2ban sqlite database prune

On servers where fail2ban has been working for a long time, you might notice the size of its database eating up your disk space. I just found one that had ballooned to over 2Gb over the course of a year.

If its causing you anguish, then you can easily prune it with the following commands

sqlite3 /var/lib/fail2ban/fail2ban.sqlite3 "delete from bans where timeofban <= strftime('%s', date('now', '-90 days'));"
sqlite3 /var/lib/fail2ban/fail2ban.sqlite3 "vacuum;"

That will delete all entries over 90 days. You may want to put it into a script run by cron, in which case include the path to sqlite eg. /usr/bin/sqlite3

Leave a Comment