Backing Up GUI Configuration

From VoIPmonitor.org
Revision as of 17:35, 30 June 2025 by Festr (talk | contribs) (Festr moved page Backup to Backing Up GUI Configuration)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search


This guide provides a step-by-step method for creating regular, automated backups of your VoIPmonitor GUI's configuration. This includes users, sensors, capture rules, and all other settings configured through the web interface.

Overview

This backup procedure is designed to save only the GUI's configuration data, not the call data (CDRs) or captured PCAP files. It is an essential part of a disaster recovery plan, allowing you to quickly restore a known-good GUI configuration to a new or rebuilt server without backing up terabytes of call data.

The process uses a command-line PHP script included with the GUI to export three types of data:

  1. Configuration Tables: The core database tables that store settings (e.g., `users`, `sensors`, `filter_ip`).
  2. Data Tables: Supporting data like chart configurations and saved reports.
  3. Configuration Files: The PHP configuration files from the GUI directory itself (e.g., `configuration.php`).

Step 1: Create the Backup Script

First, create a shell script that will run the export commands.

Create and edit the script file
nano /usr/local/sbin/backup_voipmonitor_gui.sh
Copy and paste the following content into the file
#!/bin/bash
#
# VoIPmonitor GUI Configuration Backup Script
#

# --- Configuration ---
# Set the base directory where backups will be stored
BACKUP_DIR="/var/backups/voipmonitor_gui"

# Set the retention period in days. Backups older than this will be deleted.
RETENTION_DAYS=30

# --- Script Logic ---

# Create the backup directory if it doesn't exist
mkdir -p "$BACKUP_DIR"

# Set the filename based on the current date
DAY=$(date "+%Y-%m-%d")
FILE_CFG_TABLES="$BACKUP_DIR/config_tables-${DAY}.sql"
FILE_DATA_TABLES="$BACKUP_DIR/data_tables-${DAY}.sql"
FILE_CFG_FILES="$BACKUP_DIR/config_files-${DAY}.tar.gz"

# Path to the GUI's run.php script
RUN_SCRIPT="/var/www/html/php/run.php"

echo "--- Starting VoIPmonitor GUI Backup for ${DAY} ---"

# Export the configuration and data tables as SQL dumps
php "$RUN_SCRIPT" backupGuiTables -t config -f "$FILE_CFG_TABLES"
php "$RUN_SCRIPT" backupGuiTables -t data -f "$FILE_DATA_TABLES"

# Backup the GUI's PHP configuration files into a compressed tarball
php "$RUN_SCRIPT" backupGuiConfigurationFiles -f "$FILE_CFG_FILES"

echo "Backup files created:"
ls -lh "$FILE_CFG_TABLES" "$FILE_DATA_TABLES" "$FILE_CFG_FILES"

# Clean up old backups
echo "--- Cleaning up backups older than ${RETENTION_DAYS} days ---"
find "$BACKUP_DIR" -type f -mtime +"$RETENTION_DAYS" -name '*-*-*-*.sql' -print -delete
find "$BACKUP_DIR" -type f -mtime +"$RETENTION_DAYS" -name '*-*-*-*.tar.gz' -print -delete

echo "--- Backup complete ---"

Step 2: Make the Script Executable

Set the correct permissions so the script can be run.

chmod +x /usr/local/sbin/backup_voipmonitor_gui.sh

You can test the script by running it manually: `/usr/local/sbin/backup_voipmonitor_gui.sh`. It should create three new files in `/var/backups/voipmonitor_gui`.

Step 3: Schedule the Automated Backup with Cron

The final step is to create a cron job to run the script automatically every night.

Edit the system's crontab file
crontab -e
Add the following line to the end of the file

This example will run the backup script every day at 3:30 AM.

30 3 * * * /usr/local/sbin/backup_voipmonitor_gui.sh > /var/log/voipmonitor_backup.log 2>&1
  • The `> /var/log/voipmonitor_backup.log 2>&1` part redirects all output (both standard and error) to a log file, which is essential for troubleshooting the cron job if it fails.

Save and close the file. The cron daemon will automatically pick up the new schedule.

How to Restore from a Backup

Restoring the configuration is a manual process that involves importing the SQL files and extracting the configuration files.

Warning: This process will overwrite your existing GUI settings. Perform these steps on a freshly installed GUI or be prepared to lose current configurations.

1. Restore the Database Tables

Use the `mysql` command-line client to import the saved SQL dumps into your `voipmonitor` database.

mysql -u your_user -p voipmonitor < /var/backups/voipmonitor_gui/config_tables-YYYY-MM-DD.sql
mysql -u your_user -p voipmonitor < /var/backups/voipmonitor_gui/data_tables-YYYY-MM-DD.sql
2. Restore the Configuration Files

Extract the backed-up PHP configuration files into your GUI's web root.

# Navigate to the GUI's root directory (path may vary)
cd /var/www/html/

# Extract the archive, overwriting existing files
tar xzf /var/backups/voipmonitor_gui/config_files-YYYY-MM-DD.tar.gz

After restoring both the database and files, your GUI's configuration should be fully recovered.

AI Summary for RAG

Summary: This guide provides a comprehensive, step-by-step method for creating automated daily backups of the VoIPmonitor GUI configuration. It clarifies that this process backs up settings, users, and rules, but not the call data (CDRs) or PCAP files. The core of the guide is a robust shell script that uses the GUI's built-in `run.php` command-line tool to export configuration tables, data tables, and PHP configuration files. The provided script also includes an automated cleanup feature to delete backups older than a configurable number of days. The tutorial details how to create this script, make it executable, and schedule it to run daily using a system cron job. Critically, it also includes a new section explaining the manual process for restoring the configuration from these backup files, which involves importing the SQL dumps and extracting the configuration file archive. Keywords: backup, restore, configuration, gui, settings, users, sensors, capture rules, cron, crontab, automation, disaster recovery, `run.php`, `backupGuiTables`, `backupGuiConfigurationFiles`, mysql, import, export Key Questions:

  • How do I back up my VoIPmonitor GUI configuration?
  • How can I save all my users, sensors, and settings?
  • Is there a script to automatically back up VoIPmonitor settings?
  • How do I schedule a daily backup using cron?
  • How do I restore my GUI configuration from a backup?
  • What does the `backupGuiTables` command do?
  • Does this backup include my call recordings (CDRs/PCAPs)?