Skip to content

Archive and purge old CDRs

Call records grow every day, and a database full of old CDRs slows down reports and fills the disk. The Data Retention settings move old CDRs out of the database into archive files and later delete the archives. This tutorial sets the periods for your switch. Allow 10 minutes.

Two words are used throughout:

  • Archive: the CDRs are removed from the database and saved to a compressed archive file on the switch.
  • Purge: the archive file is deleted for good.
  • You have Administrator access to the panel. The settings apply to the environment you are logged in to.
  • You know how long you must keep call records, for example for invoicing disputes or by law.
  • You know how long you need CDRs in the panel and in reports. Archived CDRs are no longer shown there.

There are four CDR periods. Each can be set from 1 day to 5 years.

Field Applies to Default
Archive All CDRs in All CDRs, with or without duration 3 months
Archive Zero CDRs in CDRs with zero duration: failed and unanswered calls 3 months
Purge All CDRs in Archive files of all CDRs 2 years
Purge Zero CDRs in Archive files of zero-duration CDRs 2 years

Zero-duration CDRs are most of the records on a wholesale switch and are rarely needed after a few weeks, so it is common to archive and purge them sooner than the others.

The panel enforces three rules when you save:

  • Purge All CDRs in must not be shorter than Archive All CDRs in.
  • Purge Zero CDRs in must not be shorter than Archive Zero CDRs in.
  • Purge All CDRs in must not be shorter than Purge Zero CDRs in.
  1. Open System Management → System Parameters.
  2. Click Backup, Data Retention.
  3. Under Data Retention, select the four CDR periods.
  4. Click Save.
Screenshot "tutorials/backup-data-retention" has not been generated yet — see scripts/screenshots/screens.yml.

Result: from the next hourly cleanup run, CDRs older than the archive periods leave the database.

For example, with Archive All CDRs in 6 months, Archive Zero CDRs in 1 month, Purge All CDRs in 2 years and Purge Zero CDRs in 1 year:

Age of the call Zero-duration CDR CDR with duration
Up to 1 month In the database In the database
1 to 6 months In an archive file In the database
6 months to 1 year In an archive file In an archive file
1 to 2 years Deleted In an archive file
Over 2 years Deleted Deleted

The switch stores CDRs in blocks of time and archives a whole block at once, so a record can stay in the database a little longer than the period.

The same section removes other old data:

Field What is deleted Default
Purge Old Rates in Tariff rates whose expiration date is older than the period, once a day 6 months
Purge Old Routes in Routes of termination routes whose expiration date is older than the period, once a day 6 months
Purge Old Invoices in Invoices older than the period, from 1 month to 5 years 1 year

Rerate tasks on Tools & Debugs → Rerate CDRs are deleted after the Purge All CDRs in period too.

The archive files are in /var/backups/env<N>/ on the switch, where <N> is the number of the environment, next to the database backups. Each file is named archive-<table>-<YYYYMMDD>.sql.bz2: an SQL dump of one block of CDRs, compressed with bzip2, dated with the newest call in it. Ask FlySIP support if you need archived CDRs loaded back into a database.

  1. Open Reports → Call Records (CDRs) and select a period older than Archive All CDRs in.
  2. Check that the list is empty for that period.
  3. Select a recent period and check that the CDRs are still there.