Skip to content

Retention Policies & Automated Storage Cleanup ​

RUSEON Core features an automated background retention scheduler (internal/recorder/) that continuously monitors disk utilization, enforces data retention policies, and prevents storage exhaustion.


Retention Strategies ​

RUSEON Core supports two complementary retention triggers configured in config.yaml:

1. Time-Based Retention (retention_days) ​

  • Enforces maximum storage duration per camera or globally.
  • Recordings older than retention_days (calculated from directory date and file epoch) are deleted on the next retention cycle.
  • Example: Setting retention_days: 30 guarantees recordings beyond 30 days are automatically purged.

2. Capacity-Based Quota (min_disk_free_gb / max_disk_usage_percent) ​

  • Prevents storage volumes from reaching 100% capacity, which would freeze database writes or crash the OS.
  • If free disk space drops below min_disk_free_gb (e.g. 20 GB) or usage exceeds max_disk_usage_percent (e.g. 90%), the retention engine immediately triggers emergency FIFO pruning, deleting the oldest hourly recording directories until target free space is restored.

The Pruning Algorithm ​

  1. Chronological Traversal (FIFO): The cleaner navigates the Storage File Layout starting from the oldest {YYYY}/{MM}/{DD}/{HH} directory.
  2. Atomic Deletion: Deletes both the .mp4 video container and the accompanying .idx sidecar file.
  3. Empty Folder Pruning: Automatically removes emptied hour, day, and month directories to keep the filesystem clean.
  4. Database Sync: Removes deleted file records from the BadgerDB index so the REST API and UI timeline update immediately.
  5. Prometheus Metrics: Emits ruseon_retention_deleted_bytes_total and ruseon_retention_deleted_files_total.

Configuration Reference ​

yaml
recording:
  enabled: true
  storage_path: "/data/recordings"
  
  # Time retention limit in days (0 = unlimited, bounded only by disk space)
  retention_days: 14

  # Emergency disk space safety thresholds
  min_disk_free_gb: 25
  max_disk_usage_percent: 90

  # Frequency of the cleanup cycle
  cleanup_interval: "10m"

Released under the MIT License.