Backup & Restore
Relevant source files
The following files were used as context for generating this wiki page:
The Backup & Restore system in the IT Management System provides a multi-layered approach to data protection, combining automated physical media tracking with digital database snapshot capabilities. It serves two primary functions: tracking physical server backup tapes for compliance and providing administrative tools for generating, downloading, and restoring SQL database dumps.
The system is split between the Backup Tape Log module, which manages daily physical rotations and ISM (Information Security Management) compliance, and the Settings module, which acts as the technical hub for database-level maintenance.
Sources: modules/settings/index.php:12-16, modules/backup_tape_log/AGENT_NOTES.md:4-6, README.md:126-127
Database Backup and Recovery
The Settings module provides comprehensive tools for managing SQL database snapshots. This system is role-restricted to Admin and IT Management users due to the sensitive nature of the data involved.
Backup Architecture and Logic
Backups are generated as plain-text SQL files containing CREATE TABLE structures, DROP TABLE commands for restoration safety, and INSERT statements for the actual data. The system utilizes a custom PHP implementation rather than relying on external system calls like mysqldump.
The backup process explicitly disables foreign key checks (SET FOREIGN_KEY_CHECKS=0) at the start of the dump to ensure that the restore process does not fail due to circular dependencies or constraint violations during data insertion.
Sources: modules/settings/index.php:143-157, modules/settings/index.php:269-284, modules/settings/AGENT_NOTES.md:16-17
Core Backup Functions
The system utilizes several key internal functions to manage SQL data:
| Function | Purpose |
|---|---|
backup_filename() | Generates a timestamped filename following the pattern backup_d_M_Y_His.sql. |
build_sql_backup($conn, $companyId) | Scans the database and constructs a full SQL string including structures and data. |
apply_sql_file($conn, $sqlText) | Parses and executes multi-statement SQL files, handling custom delimiters for triggers. |
Sources: modules/settings/index.php:137-142, modules/settings/index.php:143-157, modules/settings/index.php:223-233
The Restore Process
Restoration involves uploading an .sql file which is then parsed line-by-line. The parser is designed to identify DELIMITER changes, which are essential for restoring database triggers correctly. It filters out comments and empty lines before executing each statement against the MySQL connection.
Backup Tape Log
The Backup Tape Log module manages the physical aspect of the backup strategy. It tracks the rotation of server backup tapes on a monthly grid view, ensuring that tapes are inserted and returned to a safe location.
Workflow and Permissions
Access to the tape log is strictly controlled. While regular users can view logs, only Admin and IT Department staff can modify records for past dates or perform ISM reviews.
Tape Tracking Fields
The system tracks several specific attributes for each daily backup entry:
| Field | Description | Constraints |
|---|---|---|
time_tape_inserted | Timestamp when the tape was placed in the server. | Auto-filled via 🕒 button. |
time_returned_to_safe | Timestamp when the tape was secured. | Critical for ISM compliance. |
backup_status | Status of the job: Full, Part, or Fail. | Restricted to Admin/IT staff. |
ism_review | Boolean flag indicating the log has been reviewed. | Restricted to Admin/IT staff. |
Sources: modules/backup_tape_log/index.php:87-92, modules/backup_tape_log/index.php:470-496, modules/backup_tape_log/AGENT_NOTES.md:46-47
Data Recovery and Maintenance Tools
Beyond standard backups, the system includes administrative tools in the Settings module to verify and seed the database environment.
Maintenance Actions
Administrators can perform the following actions to ensure environment stability:
- Create Missing Tables: An idempotent process that verifies the existence of required system tables like
ui_configurationand creates them if missing. - Add Sample Data: Seeds empty tables with initial data derived from
database.sqlfor testing purposes. - Analyze Database Health: A utility script (
analyze_database_health.php) that runsANALYZE TABLEon all base tables to detect corruption or "doesn't exist in engine" errors.
Sources: modules/settings/index.php:431-443, modules/settings/index.php:451-468, scripts/scripts.php:364-369, README.md:145-152
Summary
The Backup & Restore system provides a dual-layer protection strategy. For physical security and compliance, the Backup Tape Log ensures server rotations are documented with strict timestamping rules. For digital disaster recovery, the Settings module provides self-contained SQL export and import tools that allow administrators to move data between environments or recover from failures without external dependencies. Both systems leverage the system's multi-tenant architecture, ensuring that backup files and tape logs are appropriately scoped to specific companies.
Sources: modules/settings/AGENT_NOTES.md:4-7, modules/backup_tape_log/AGENT_NOTES.md:4-6