{"id":19,"date":"2006-10-11T00:00:00","date_gmt":"2006-10-11T00:00:00","guid":{"rendered":"http:\/\/netexpertise\/en\/?p=19"},"modified":"2021-10-10T19:12:17","modified_gmt":"2021-10-10T17:12:17","slug":"archive","status":"publish","type":"post","link":"http:\/\/www.netexpertise.eu\/en\/database\/mysql\/archive.html","title":{"rendered":"Archive Accounting Records in Freeradius"},"content":{"rendered":"\n<p>Logging Radius accounting into <a href=\"\/en\/category\/database\/mysql\">Mysql<\/a> database can fill up a lot of space. Some performance issues will arise at some stage as well, especially if traffic reporting scripts are to be added to the overall system. That&#8217;s why we added a new table to archive older Freeradius accounting records.<br><br><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img decoding=\"async\" src=\"\/uploads\/archive-boxes-shelf-folders-1850170.jpg\" alt=\"Archive Freeradius Accounting\"\/><figcaption><a href=\"https:\/\/pixabay.com\/users\/Pexels\">Pexels<\/a> \/ Pixabay<\/figcaption><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><br>Motivations<\/h2>\n\n\n\n<p>We can of course delete all records older than a certain amount of time. However, we work with ISPs and accounting can provide these 2 important features:<br>&#8211; Traffic reporting for customers<br>&#8211; Past information about IP addresses ownership<br>Not sure how long ISPs are supposed to keep this last information legally, but 3 months should be a good compromise. Why not just deleting data older than 3 months? It might be just personnal but I like to keep all data for future checks. Someone might complain that he&#8217;s been charged and hasn&#8217;t used the connection in the last 10 months. How would we check he&#8217;s saying the truth?<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><br>Creating the New Archive Table<\/h2>\n\n\n\n<p>We start from a proper <a href=\"\/en\/category\/networking\/freeradius\">FreeRadius<\/a> installation running with a Mysql database. Accounting is stored in the Radacct table. Mysql provides a storage engine that can handle large amount of data like logs. The <a href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.0\/en\/archive-storage-engine.html\">ARCHIVE<\/a> engine doesn&#8217;t support deletion nor indexing so queries would run slower obviously. This is a minor issue as we rarely want to access this table. On the other hand, data is compressed so it takes very little space. You can find a very good article about storage engines written by Robin Schumacher, MySQL&#8217;s Director of Product Management, at <a href=\"http:\/\/dev.mysql.com\/tech-resources\/articles\/storage-engine.html\">http:\/\/dev.mysql.com\/tech-resources\/articles\/storage-engine.html<\/a>. Here&#8217;s the table creation code (Check it matches last Freeradius radacct table version):<br><br><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"sql\" class=\"language-sql\">CREATE TABLE `radacctold` (\n  `RadAcctId` bigint(21) NOT NULL,\n  `AcctSessionId` varchar(128) default NULL,\n  `AcctUniqueId` varchar(32) NOT NULL default '',\n  `UserName` varchar(64) NOT NULL default '',\n  `Realm` varchar(64) default '',\n  `NASIPAddress` varchar(15) NOT NULL default '',\n  `NASPortId` int(12) default NULL,\n  `NASPortType` varchar(32) default NULL,\n  `AcctStartTime` datetime NOT NULL default '0000-00-00 00:00:00',\n  `AcctStopTime` datetime NOT NULL default '0000-00-00 00:00:00',\n  `AcctSessionTime` int(12) default NULL,\n  `AcctAuthentic` varchar(32) default NULL,\n  `ConnectInfo_start` varchar(32) default NULL,\n  `ConnectInfo_stop` varchar(32) default NULL,\n  `AcctInputOctets` int(12) unsigned default NULL,\n  `AcctOutputOctets` bigint(12) default NULL,\n  `CalledStationId` varchar(50) NOT NULL default '',\n  `CallingStationId` varchar(50) NOT NULL default '',\n  `AcctTerminateCause` varchar(32) NOT NULL default '',\n  `ServiceType` varchar(32) default NULL,\n  `FramedProtocol` varchar(32) default NULL,\n  `FramedIPAddress` varchar(15) NOT NULL default '',\n  `AcctStartDelay` int(12) default NULL,\n  `AcctStopDelay` int(12) default NULL\n) ENGINE = ARCHIVE;<\/code><\/pre>\n\n\n\n<p><br>It is basically a copy of the original table with no index and no primary key. Only the storage engine is different.<br><em>Note<\/em> You can check the archive engine is available on your installation with the following statement: <em>SHOW ENGINES;<\/em>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><br>Moving Accounting Data Across<\/h2>\n\n\n\n<p>Second step is to migrate old data from the orginal to the previously created table. A simple stored procedure can do the job:<br><br><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"sql\" class=\"language-sql\">CREATE PROCEDURE radius.archive_acct()\nBEGIN\n  INSERT INTO radacctold\n    SELECT * FROM radacct\n    WHERE acctstoptime &gt; 0\n    AND date(acctstarttime) &lt; (CURDATE() - INTERVAL 3 MONTH);\n  DELETE FROM radacct\n    WHERE acctstoptime &gt; 0\n    AND date(acctstarttime) &lt; (CURDATE() - INTERVAL 3 MONTH);\nEND<\/code><\/pre>\n\n\n\n<p><br>Launch the procedure once a day and you&#8217;re sorted for a while. No maintenance needed and good performance remain. You can also modify it just to delete old records.<br>At the time of this writting Mysql5.1 is still in Beta version so we won&#8217;t use events to fire up the script. A simple cron job does the job in the meantime.<br>I suggest you split the table in multiple partitions (Archive engine supports <a href=\"https:\/\/dev.mysql.com\/doc\/refman\/5.7\/en\/partitioning.html\" target=\"_blank\" rel=\"noreferrer noopener\">partitioning<\/a>) for faster queries and get the ability to delete older data based on years. Archive Freeradius accounting is fairly easy.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Logging Radius accounting into Mysql database can fill up a lot of space. Some performance issues will arise at some stage as well, especially if traffic reporting scripts are to be added to the overall system. That&#8217;s why we added a new table to archive older Freeradius accounting records. Motivations We can of course delete [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[3,4],"tags":[12,5,384,386,385,10],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.8.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Netexpertise - Archive Accounting Records in Freeradius<\/title>\n<meta name=\"description\" content=\"Archive Freeradius accounting records, save space with the archive engine, and get better overall performance\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/www.netexpertise.eu\/en\/database\/mysql\/archive.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Netexpertise - Archive Accounting Records in Freeradius\" \/>\n<meta property=\"og:description\" content=\"Archive Freeradius accounting records, save space with the archive engine, and get better overall performance\" \/>\n<meta property=\"og:url\" content=\"http:\/\/www.netexpertise.eu\/en\/database\/mysql\/archive.html\" \/>\n<meta property=\"og:site_name\" content=\"Netexpertise\" \/>\n<meta property=\"article:published_time\" content=\"2006-10-11T00:00:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-10-10T17:12:17+00:00\" \/>\n<meta name=\"author\" content=\"dave\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@netexpertise\" \/>\n<meta name=\"twitter:site\" content=\"@netexpertise\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"http:\/\/www.netexpertise.eu\/en\/database\/mysql\/archive.html\",\"url\":\"http:\/\/www.netexpertise.eu\/en\/database\/mysql\/archive.html\",\"name\":\"Netexpertise - Archive Accounting Records in Freeradius\",\"isPartOf\":{\"@id\":\"https:\/\/www.netexpertise.eu\/en\/#website\"},\"datePublished\":\"2006-10-11T00:00:00+00:00\",\"dateModified\":\"2021-10-10T17:12:17+00:00\",\"author\":{\"@id\":\"https:\/\/www.netexpertise.eu\/en\/#\/schema\/person\/cb4cd666549d22e9070ec1cfc1a496fa\"},\"description\":\"Archive Freeradius accounting records, save space with the archive engine, and get better overall performance\",\"breadcrumb\":{\"@id\":\"http:\/\/www.netexpertise.eu\/en\/database\/mysql\/archive.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/www.netexpertise.eu\/en\/database\/mysql\/archive.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/www.netexpertise.eu\/en\/database\/mysql\/archive.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.netexpertise.eu\/en\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Archive Accounting Records in Freeradius\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.netexpertise.eu\/en\/#website\",\"url\":\"https:\/\/www.netexpertise.eu\/en\/\",\"name\":\"Netexpertise\",\"description\":\"Systems \/ Networks \/ DevOps\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.netexpertise.eu\/en\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.netexpertise.eu\/en\/#\/schema\/person\/cb4cd666549d22e9070ec1cfc1a496fa\",\"name\":\"dave\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.netexpertise.eu\/en\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/1.gravatar.com\/avatar\/1129916e1f4955bd632f27f836f64e55?s=96&d=mm&r=g\",\"contentUrl\":\"http:\/\/1.gravatar.com\/avatar\/1129916e1f4955bd632f27f836f64e55?s=96&d=mm&r=g\",\"caption\":\"dave\"},\"sameAs\":[\"http:\/\/www.netexpertise.eu\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Netexpertise - Archive Accounting Records in Freeradius","description":"Archive Freeradius accounting records, save space with the archive engine, and get better overall performance","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/www.netexpertise.eu\/en\/database\/mysql\/archive.html","og_locale":"en_US","og_type":"article","og_title":"Netexpertise - Archive Accounting Records in Freeradius","og_description":"Archive Freeradius accounting records, save space with the archive engine, and get better overall performance","og_url":"http:\/\/www.netexpertise.eu\/en\/database\/mysql\/archive.html","og_site_name":"Netexpertise","article_published_time":"2006-10-11T00:00:00+00:00","article_modified_time":"2021-10-10T17:12:17+00:00","author":"dave","twitter_card":"summary_large_image","twitter_creator":"@netexpertise","twitter_site":"@netexpertise","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"http:\/\/www.netexpertise.eu\/en\/database\/mysql\/archive.html","url":"http:\/\/www.netexpertise.eu\/en\/database\/mysql\/archive.html","name":"Netexpertise - Archive Accounting Records in Freeradius","isPartOf":{"@id":"https:\/\/www.netexpertise.eu\/en\/#website"},"datePublished":"2006-10-11T00:00:00+00:00","dateModified":"2021-10-10T17:12:17+00:00","author":{"@id":"https:\/\/www.netexpertise.eu\/en\/#\/schema\/person\/cb4cd666549d22e9070ec1cfc1a496fa"},"description":"Archive Freeradius accounting records, save space with the archive engine, and get better overall performance","breadcrumb":{"@id":"http:\/\/www.netexpertise.eu\/en\/database\/mysql\/archive.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/www.netexpertise.eu\/en\/database\/mysql\/archive.html"]}]},{"@type":"BreadcrumbList","@id":"http:\/\/www.netexpertise.eu\/en\/database\/mysql\/archive.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.netexpertise.eu\/en"},{"@type":"ListItem","position":2,"name":"Archive Accounting Records in Freeradius"}]},{"@type":"WebSite","@id":"https:\/\/www.netexpertise.eu\/en\/#website","url":"https:\/\/www.netexpertise.eu\/en\/","name":"Netexpertise","description":"Systems \/ Networks \/ DevOps","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.netexpertise.eu\/en\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.netexpertise.eu\/en\/#\/schema\/person\/cb4cd666549d22e9070ec1cfc1a496fa","name":"dave","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.netexpertise.eu\/en\/#\/schema\/person\/image\/","url":"http:\/\/1.gravatar.com\/avatar\/1129916e1f4955bd632f27f836f64e55?s=96&d=mm&r=g","contentUrl":"http:\/\/1.gravatar.com\/avatar\/1129916e1f4955bd632f27f836f64e55?s=96&d=mm&r=g","caption":"dave"},"sameAs":["http:\/\/www.netexpertise.eu"]}]}},"_links":{"self":[{"href":"http:\/\/www.netexpertise.eu\/en\/wp-json\/wp\/v2\/posts\/19"}],"collection":[{"href":"http:\/\/www.netexpertise.eu\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.netexpertise.eu\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.netexpertise.eu\/en\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.netexpertise.eu\/en\/wp-json\/wp\/v2\/comments?post=19"}],"version-history":[{"count":0,"href":"http:\/\/www.netexpertise.eu\/en\/wp-json\/wp\/v2\/posts\/19\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.netexpertise.eu\/en\/wp-json\/wp\/v2\/media?parent=19"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.netexpertise.eu\/en\/wp-json\/wp\/v2\/categories?post=19"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.netexpertise.eu\/en\/wp-json\/wp\/v2\/tags?post=19"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}