Periodically Delete CDRs Older than N Months

@erobertus This post should have been in a new thread in tips and tricks as opposed to necro-posting to 6 year old thread.

I and others in support have done similar operations to cdr/cel tables over the years, and would use commands like this

CREATE TABLE new_cdr LIKE cdr;
INSERT INTO new_cdr SELECT * FROM cdr WHERE calldate >= CURDATE() - INTERVAL 3 MONTH;
RENAME TABLE cdr TO cdr_old, cdr_new TO cdr;

which are certainly simpler and more fault tolerant in case the tables on the system have been altered from what the script is expecting.

1 Like