Security Fundamentals

Plan Data Retention and Secure Deletion in PHP Systems

Define how application records, uploads, logs and backups are retained and deleted without leaving unmanaged copies behind.

Retention is a system-wide concern

Deleting a row from the primary database does not necessarily remove the same data from exports, object storage, logs, caches, search indexes or backups. A retention policy should identify every place where the data can exist.

Define categories and periods

Classify data by purpose and sensitivity. Set retention periods based on operational needs and applicable legal obligations. Do not keep information indefinitely simply because storage is inexpensive. Avoid inventing one universal period for all data types.

Automate deletion carefully

Use scheduled jobs that select eligible records in bounded batches. Record the deletion outcome without copying the sensitive content into the audit log. Consider foreign-key relationships and dependent files before removing a parent record.

Account for backups

Backups may retain deleted records until their retention window expires. Document this behavior and ensure restored backups reapply deletion requests or retention rules where required. Protect backup access and encryption keys.

Verify deletion

Create tests and periodic checks for orphaned files, expired exports and stale cache entries. Define how the system handles legal holds or other approved exceptions without making retention indefinite by default.

Checklist

  • Inventory every storage location.
  • Define purpose-based retention periods.
  • Automate bounded deletion jobs.
  • Handle dependent files and indexes.
  • Document backup expiration behavior.
  • Reapply deletion rules after restoration where required.
  • Test and audit the deletion process.

References

OWASP Logging Cheat Sheet · NIST Privacy Framework

Share this page Help other developers discover this resource.