Create a script called (for example) “DeleteCDR8Mos.sql” in your “asterisk root directory” or in the “root” home directory. The example below assumes it’s in the “/root” directory.
use asteriskcdrdb;
repair table cdr;
repair table cel;
delete from cdr where calldate < DATE_SUB(NOW(), INTERVAL 6 MONTH);
delete from cel where eventtime < DATE_SUB(NOW(), INTERVAL 6 MONTH);
optimize table cdr;
optimize table cel;
exit;
In your crontab on the server (important part, since access to the database is limited to localhost), add something like:
X X X X X X mysql -u root asteriskcdrdb < /root/DeleteCDR8Mos.sql
The “X” entries are there for your time/date/day entries - salt to taste.
That should get you started.