{"id":551,"date":"2020-02-24T17:42:51","date_gmt":"2020-02-24T09:42:51","guid":{"rendered":"https:\/\/play.datalude.com\/blog\/?p=551"},"modified":"2021-02-23T11:49:15","modified_gmt":"2021-02-23T03:49:15","slug":"fail2ban-sqlite-database-prune","status":"publish","type":"post","link":"https:\/\/play.datalude.com\/blog\/2020\/02\/fail2ban-sqlite-database-prune\/","title":{"rendered":"fail2ban sqlite database prune"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">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. You'll find it hiding in \/var\/lib\/fail2ban\/<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ls -hal \/var\/lib\/fail2ban\/<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If its causing you anguish, then you can easily prune it with the following commands. Obviously you'll need to install sqlite3 first if its not installed.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sqlite3 \/var\/lib\/fail2ban\/fail2ban.sqlite3 \"delete from bans where timeofban &lt;= strftime('%s', date('now', '-90 days'));\"\nsqlite3 \/var\/lib\/fail2ban\/fail2ban.sqlite3 \"vacuum;\"<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">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<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Update Feb 2021<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">I read a post elsewhere where someone wanted to remove all fail2ban history and start fresh. In that case the magic commands are &#8230; with sudo as required. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>systemctl stop fail2ban\ntruncate -s 0 \/var\/log\/fail2ban.log\nrm \/var\/lib\/fail2ban\/fail2ban.sqlite3\nsystemctl start fail2ban<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>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. You'll find it hiding in \/var\/lib\/fail2ban\/ If its causing you anguish, then you can easily &#8230; <a title=\"fail2ban sqlite database prune\" class=\"read-more\" href=\"https:\/\/play.datalude.com\/blog\/2020\/02\/fail2ban-sqlite-database-prune\/\" aria-label=\"Read more about fail2ban sqlite database prune\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[1,4],"tags":[],"class_list":["post-551","post","type-post","status-publish","format-standard","hentry","category-it","category-linux"],"_links":{"self":[{"href":"https:\/\/play.datalude.com\/blog\/wp-json\/wp\/v2\/posts\/551","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/play.datalude.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/play.datalude.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/play.datalude.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/play.datalude.com\/blog\/wp-json\/wp\/v2\/comments?post=551"}],"version-history":[{"count":0,"href":"https:\/\/play.datalude.com\/blog\/wp-json\/wp\/v2\/posts\/551\/revisions"}],"wp:attachment":[{"href":"https:\/\/play.datalude.com\/blog\/wp-json\/wp\/v2\/media?parent=551"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/play.datalude.com\/blog\/wp-json\/wp\/v2\/categories?post=551"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/play.datalude.com\/blog\/wp-json\/wp\/v2\/tags?post=551"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}