menu_book Navigation menu

Backups

Data safety is built into the core infrastructure of Pragma CMS. Backups are handled through two distinct channels: Server-level automation and Application-level manual generation.

1. Automated Daily Backups (Server-Level)

During the server installation (install_server.sh), Pragma configures a daily Cron job (scripts/cron/backup.sh) executed at 03:00 AM.

This script performs a deep, intelligent backup:

  • Database: It loops through all active databases, ignoring system schemas (information_schema, performance_schema), and runs a compressed mysqldump.
  • Files: It creates a tar.gz archive of the entire /var/www/pragma-cms directory. It deliberately excludes ephemeral data (storage/cache, storage/logs, storage/tmp) to keep the backup lightweight.
  • Retention Policy: It automatically prunes backup files older than 7 days to preserve server disk space.

2. Manual On-Demand Backups (Admin UI)

Administrators can request a full backup directly from the UI (Admin > Tools > Backup).

Unlike many PHP tools that crash due to memory limits (OOM) when exporting large databases, Pragma CMS uses a Memory-Safe PHP Stream approach:

  1. Direct Stream Writing: It writes INSERT statements directly to the disk (fopen/fwrite) row by row using a PDO cursor (fetch instead of fetchAll). This means a 5GB database only consumes a few megabytes of RAM during the export.
  2. Relational Integrity: The generated SQL file automatically disables Foreign Key Checks (SET FOREIGN_KEY_CHECKS = 0) at the top, ensuring that restoring the database later will not fail due to table creation order.
  3. Binary Safety: Every value is passed through PDO::quote() to prevent encoding corruption during export.
  4. On-the-fly ZIP: The generated SQL file is bundled into a ZIP archive along with the /media and /uploads directories, then served directly to the browser.