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 compressedmysqldump. - Files: It creates a
tar.gzarchive of the entire/var/www/pragma-cmsdirectory. 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:
- Direct Stream Writing: It writes
INSERTstatements directly to the disk (fopen/fwrite) row by row using a PDO cursor (fetchinstead offetchAll). This means a 5GB database only consumes a few megabytes of RAM during the export. - 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. - Binary Safety: Every value is passed through
PDO::quote()to prevent encoding corruption during export. - On-the-fly ZIP: The generated SQL file is bundled into a ZIP archive along with the
/mediaand/uploadsdirectories, then served directly to the browser.