Limit Call logs for 90 Days

Hello all,

My manager asked me to limit call logs for only 90 days due to the data privacy policy in our company. Is there any possibility to do this automatically? After 90 days the record of any call is deleted?

FreePBX 15.0.21

mysql -uroot -p
use asteriskcdrdb;
delete from cdr where calldate < DATE_SUB(NOW(), INTERVAL 3 MONTH);
delete from cel where eventtime < DATE_SUB(NOW(), INTERVAL 3 MONTH);

Hi Edmond,

it is MySQL stuff, I am not very much into this database thing. Can you guide me on how can I make this run on the FreePBX command line in form of some prepaid script or cronjob? That I don’t have to do it regularly instead of an automatic operation.


i think you can do something like this in cronjob:

mysql --user=[username] --password=[password] --database=[db name] --execute="delete from cdr where calldate < DATE_SUB(NOW(), INTERVAL 3 MONTH);"

Without saving credentials and using the magic of internals…


include '/etc/freepbx.conf';
if($argc < 2) {
    echo "Usage: $argv[0] <months>\n";

/** A Small cheat to get the cdr database without seperately storing credentials or parsing anything */
$cdrdb = FreePBX::Cdr()->cdrdb;

$query = sprintf("DELETE FROM cdr WHERE calldate < DATE_SUB(NOW(), INTERVAL %s MONTH);", $argv[1]);


^^^ Make executable ^^^

0 0 * * * /path/to/prunecdr.php 3

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.