DEV Community

Cover image for Asterisk Call Recording Storage: Retention & Encryption
Muhammad Ali Mughal
Muhammad Ali Mughal

Posted on

Asterisk Call Recording Storage: Retention & Encryption

Call recordings are the part of a phone system nobody plans until something goes wrong. The disk on the PBX fills up and recording stops without a warning. A customer asks for their data to be deleted and nobody knows which files are theirs. An auditor asks who can listen to calls and the honest answer is "anyone with SSH." Asterisk call recording storage is a design problem, not a checkbox.

I run Loop Origin, a software company that builds and maintains Asterisk and FreePBX phone systems and contact center software. I wrote this with help from AI tools and checked every command and config myself. This guide covers one problem: storing Asterisk call recordings so they stay small, searchable, encrypted and deleted on schedule.

How should I store Asterisk call recordings?

Direct answer: Record with MixMonitor to local disk, then run a post-recording script that compresses each file (for example to Opus or MP3), encrypts it, uploads it to object storage and records the location in your database. Enforce retention with storage lifecycle rules, serve playback through short-lived signed URLs, and alert when the local spool grows.

How Asterisk records, and where it goes wrong

In most installs the MixMonitor application does the recording. It writes a single mixed file of both call legs while the call runs. FreePBX, by default, stores these under /var/spool/asterisk/monitor/YYYY/MM/DD/ and writes the file name into the recordingfile column of the CDR table, so its reports can play them back.

That default is fine for a small office. It breaks at contact center volume for four reasons:

  1. Size. Uncompressed 8 kHz, 16-bit mono WAV is 128 kbit/s, about 0.96 MB per minute. It adds up fast.
  2. One disk. Recordings, logs, the database and the OS all share the PBX disk. When it fills, recording fails and other services can fail with it.
  3. No retention. Nothing deletes old files unless someone writes a cron job, and that job usually ignores legal holds.
  4. Flat access. Anyone with shell or web admin access can read every call.

The storage math, worked as an example

Here is an example for a 20-agent team that handles about 300 recorded minutes per agent per working day (6,000 minutes a day, 22 working days a month). The bitrates are the codec settings, so the sizes follow directly; plug in your own minutes.

Format Bitrate (mono) Per minute Per day (6,000 min) Per month (22 days)
WAV, 8 kHz 16-bit PCM 128 kbit/s ~0.96 MB ~5.8 GB ~127 GB
MP3 32 kbit/s ~0.24 MB ~1.4 GB ~32 GB
Opus 16 kbit/s ~0.12 MB ~0.7 GB ~16 GB

For phone-quality audio (8 kHz to begin with), speech at 16 to 32 kbit/s is usually clear enough for QA and disputes. Test a few real calls with your QA team before you commit to a bitrate. Keep the format your playback tools and any speech analytics vendor can read.

The pipeline: record local, process, ship, index

Recording directly to network storage is tempting, but a slow NFS mount can stall the audio write path during a call. Record to local disk, then move the finished file.

Step 1: record only the useful part

In a custom dialplan, the b option starts writing only when the call is bridged, so ringing and queue hold music are not stored:

exten => _X.,1,Set(REC=${STRFTIME(${EPOCH},,%Y/%m/%d)}/${UNIQUEID})
 same => n,Set(MIXMONITOR_FILENAME=/var/spool/asterisk/monitor/${REC}.wav)
 same => n,MixMonitor(${MIXMONITOR_FILENAME},b,/usr/local/bin/rec-post.sh ${UNIQUEID} ${MIXMONITOR_FILENAME})
 same => n,Dial(PJSIP/${EXTEN},30)
Enter fullscreen mode Exit fullscreen mode

The third argument to MixMonitor is a command Asterisk runs after the recording file is closed. On FreePBX, use the "Post Call Recording Script" field in Advanced Settings instead of editing generated dialplan.

Naming files by UNIQUEID instead of caller ID avoids odd characters in paths and gives you a key that already exists in the CDR.

Step 2: compress, encrypt, upload, index

#!/usr/bin/env bash
# /usr/local/bin/rec-post.sh <uniqueid> <wav_path>
set -euo pipefail
UID_="$1"; WAV="$2"
OUT="${WAV%.wav}.opus"
ffmpeg -nostdin -loglevel error -i "$WAV" -ac 1 -c:a libopus -b:a 16k "$OUT"
# client-side encryption with age; the private key never lives on the PBX
age -r "$(cat /etc/rec/recipient.pub)" -o "$OUT.age" "$OUT"
KEY="recordings/$(date -u +%Y/%m/%d)/$UID_.opus.age"
aws s3 cp "$OUT.age" "s3://callrec-prod/$KEY" --only-show-errors
mysql callrec -e "INSERT INTO recordings (uniqueid, object_key, created_at) VALUES ('$UID_', '$KEY', UTC_TIMESTAMP())"
rm -f "$WAV" "$OUT" "$OUT.age"
Enter fullscreen mode Exit fullscreen mode

The order matters. Delete the local WAV only after the upload and the database insert both succeed; with set -e the script stops on the first failure and leaves the file for a retry job to pick up. Run the script as the asterisk user with only the permissions it needs, and keep credentials in an instance role or a root-owned file, not in the dialplan.

A server rack with blinking status lights in a data center
AI-generated image.

Step 3: retry what failed

A small cron job every 10 minutes looks for .wav files older than 15 minutes in the spool and re-runs the post script. Anything still there after an hour should page someone, because it means uploads are failing.

Choosing where recordings live

Option Durability Retention control Access control Good for
Local PBX disk One disk, unless you add backups Manual cron jobs Shell and web admin users Small offices, short retention
NAS / NFS share Depends on the NAS and its backups Manual or NAS snapshot policies Share permissions On-site teams with existing storage
S3-compatible object storage Replicated by the provider Lifecycle rules, Object Lock for holds Per-bucket IAM, signed URLs Contact centers, compliance, multiple sites

For most contact centers, object storage wins because retention and access become configuration instead of scripts you have to remember to maintain.

Retention and deletion without surprises

Set retention by rule, not by memory:

  • Lifecycle expiration. An S3 lifecycle rule on the recordings/ prefix can delete objects after a set number of days. Put the number in your recording policy, chosen with your legal adviser, because rules differ by country and industry.
  • Legal holds. S3 Object Lock (on providers that support it) can block deletion of specific recordings that are part of a dispute, even when lifecycle rules would remove them.
  • Delete requests. Because every file is indexed by uniqueid, you can find all calls for a customer through the CDR, delete those objects and mark the rows deleted.
  • Card payments. Do not record card numbers or security codes. When an agent opens a payment screen, mute the recording through the AMI MixMonitorMute action and unmute when the payment step closes, or route payments to a separate IVR.

Encryption and playback access

Encrypt in two places. Server-side encryption on the bucket protects against lost disks at the provider. Client-side encryption (age or GPG, as in the script) means that even someone who reads the bucket cannot play the files without the private key, which lives only on the playback service.

For playback, your CRM or QA tool asks a small service for a recording by uniqueid. That service checks the user's role, logs the access, downloads and decrypts the file, and streams it or returns a URL that expires in a few minutes. I covered the CRM side of this, including call logs, in Asterisk CRM integration: screen pops, click-to-dial and logs. If you are still choosing the platform, start with planning a VoIP phone system for a small business.

Failure modes I watch for

  • Spool growth. Alert when /var/spool/asterisk/monitor passes a size or age threshold. It is the first sign uploads have stopped.
  • Silent no-record. A dialplan change removes MixMonitor from a queue. Compare daily CDR answered calls with indexed recordings; a sudden gap is a bug.
  • Clock and path drift. Use UTC in object keys so daylight saving changes do not create duplicate or missing folders.
  • Key loss. Back up the private decryption key separately and test a restore. Encrypted recordings with no key are deleted recordings.
  • Transcoding load. ffmpeg on a busy PBX competes with calls for CPU. At high volume, upload the WAV to a worker queue and transcode there.

Implementation checklist

  1. Write a recording policy: what is recorded, consent announcement, retention days, who may listen.
  2. Record with MixMonitor using the b option and UNIQUEID file names.
  3. Add a post-recording script: compress, encrypt, upload, index, then delete locally.
  4. Add a retry job and an alert on old files in the spool.
  5. Create the bucket with server-side encryption, a lifecycle rule and, if needed, Object Lock.
  6. Mute recording during card payments.
  7. Serve playback only through a service that checks roles and logs access.
  8. Reconcile CDR answered calls against indexed recordings daily.
  9. Test a restore and a deletion request end to end every quarter.

FAQ

Is WAV or MP3 better for Asterisk recordings?

Record to WAV for reliability, then convert after the call. Store Opus or MP3 for long-term retention; both cut storage by roughly four to eight times compared with WAV at the bitrates above.

Can MixMonitor write straight to S3?

Not natively. Record locally, then upload in the post-recording command. Mounting S3 as a file system for live writes adds latency and failure modes to the call path.

How long should I keep call recordings?

It depends on your country, industry and contracts. Agree a number with your legal adviser, write it into the policy and enforce it with lifecycle rules.

How do I stop recording card details?

Mute MixMonitor with the AMI MixMonitorMute action while the payment step runs, or send the caller to a separate payment IVR that is not recorded.

Does FreePBX still show recordings after I move them?

Not by default, because its CDR reports read local paths. Point playback at your own service keyed by uniqueid, or keep a short local cache window for FreePBX's built-in player.

What about recording WebRTC agents?

Recording happens on the Asterisk bridge, so browser agents are recorded the same way. See my notes on WebRTC contact center architecture for the media path.

The short version

Record locally, ship quickly, and let configuration handle the rest. Compress after the call, encrypt before upload, index by uniqueid, delete by lifecycle rule, and alert the moment the local spool starts to grow.


Follow & Connect

Watch on YouTube: Resume Boost AI · PixelValut · Daily AI News By Ali

Top comments (0)