MagicWP Docs

Backups

Comprehensive backup solutions for WordPress sites with automated and manual options

Backups

Protect your WordPress site with comprehensive backup solutions. From automated daily backups to manual downloads and restoration, ensure your data is always safe and recoverable.

Backup Overview

Why Backups Matter

Data Protection: Safeguard your content, settings, and user data Disaster Recovery: Quick restoration after site issues Migration Support: Easy site movement between servers Peace of Mind: Confidence in your site's stability Compliance: Meet data protection requirements

Backup Types

Full Site Backup

  • Complete WordPress installation: All files, database, and configurations
  • Largest backup size: Most comprehensive protection
  • Slowest restoration: Takes longest to restore
  • Best for: Complete disaster recovery

Database Only Backup

  • WordPress database: Posts, pages, users, settings
  • Smaller size: Faster to create and restore
  • Faster restoration: Quick recovery of content
  • Best for: Content and settings recovery

Files Only Backup

  • WordPress files: Themes, plugins, uploads, configurations
  • Theme/plugin recovery: Restore customizations and uploads
  • Partial recovery: Doesn't include database content
  • Best for: Code and media recovery

Automated Backup Solutions

Scheduled Backups

Daily Backups

  • Automatic execution: Runs every 24 hours
  • Minimal impact: Scheduled during low-traffic periods
  • Retention policy: Configurable retention period
  • Storage management: Automatic cleanup of old backups

Weekly Backups

  • Comprehensive coverage: Full weekly backup cycle
  • Storage efficiency: Reduces storage requirements
  • Quick recovery: Recent backup always available
  • Cost effective: Balances protection with storage costs

Monthly Archives

  • Long-term retention: Historical backup preservation
  • Compliance support: Meets regulatory requirements
  • Storage optimization: Compressed long-term archives
  • Audit trail: Complete backup history

Backup Scheduling

// Schedule automated backups
function schedule_backup_tasks() {
    // Daily backup at 2 AM
    if (!wp_next_scheduled('daily_backup')) {
        wp_schedule_event(strtotime('02:00:00'), 'daily', 'daily_backup');
    }

    // Weekly backup on Sunday at 3 AM
    if (!wp_next_scheduled('weekly_backup')) {
        wp_schedule_event(strtotime('next Sunday 03:00:00'), 'weekly', 'weekly_backup');
    }

    // Monthly backup on first day at 4 AM
    if (!wp_next_scheduled('monthly_backup')) {
        wp_schedule_event(strtotime('first day of next month 04:00:00'), 'monthly', 'monthly_backup');
    }
}
add_action('wp', 'schedule_backup_tasks');

// Execute backup tasks
function execute_daily_backup() {
    perform_backup('daily');
}

function execute_weekly_backup() {
    perform_backup('weekly');
}

function execute_monthly_backup() {
    perform_backup('monthly');
}

add_action('daily_backup', 'execute_daily_backup');
add_action('weekly_backup', 'execute_weekly_backup');
add_action('monthly_backup', 'execute_monthly_backup');

Manual Backup Options

One-Click Backup

Instant Backup Creation

  • Immediate execution: Create backup instantly
  • Progress tracking: Real-time backup progress
  • Download ready: Immediate download availability
  • Storage options: Local or cloud storage

Custom Backup Configuration

  • Selective content: Choose what to backup
  • Compression options: ZIP or TAR.GZ formats
  • Encryption: Optional backup encryption
  • Naming convention: Custom backup file names

Advanced Backup Features

Incremental Backups

  • Change tracking: Only backup modified files
  • Storage efficiency: Reduce backup size and time
  • Faster restoration: Quick recovery of recent changes
  • Bandwidth savings: Minimize transfer requirements

Differential Backups

  • Base backup: Complete initial backup
  • Change accumulation: Track all changes since base
  • Efficient storage: Single differential file
  • Flexible restoration: Restore from base + differential

Download Backup Options

Direct Download

Browser Download

  • Immediate access: Download directly to browser
  • Progress indication: Download progress tracking
  • Resume capability: Resume interrupted downloads
  • Security: Secure download links with expiration

API Download

// Generate secure download link
function generate_backup_download_link($backup_id, $expiration = 3600) {
    $download_token = wp_generate_password(32, false);
    $download_url = add_query_arg(array(
        'action' => 'download_backup',
        'backup_id' => $backup_id,
        'token' => $download_token,
        'expires' => time() + $expiration
    ), admin_url('admin-ajax.php'));

    // Store token temporarily
    set_transient('backup_download_' . $download_token, array(
        'backup_id' => $backup_id,
        'expires' => time() + $expiration
    ), $expiration);

    return $download_url;
}

// Handle download request
function handle_backup_download() {
    $backup_id = sanitize_text_field($_GET['backup_id']);
    $token = sanitize_text_field($_GET['token']);
    $expires = intval($_GET['expires']);

    // Validate token
    $token_data = get_transient('backup_download_' . $token);
    if (!$token_data || $token_data['backup_id'] !== $backup_id || time() > $expires) {
        wp_die('Invalid or expired download link');
    }

    // Delete token after use
    delete_transient('backup_download_' . $token);

    // Serve backup file
    $backup_path = get_backup_file_path($backup_id);
    if (file_exists($backup_path)) {
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename="' . basename($backup_path) . '"');
        header('Content-Length: ' . filesize($backup_path));
        readfile($backup_path);
        exit;
    } else {
        wp_die('Backup file not found');
    }
}
add_action('wp_ajax_download_backup', 'handle_backup_download');
add_action('wp_ajax_nopriv_download_backup', 'handle_backup_download');

Batch Download

Multiple Backup Download

  • Bulk selection: Select multiple backups for download
  • Archive creation: Create single archive for multiple backups
  • Storage management: Automatic cleanup after download
  • Bandwidth control: Throttle download speed if needed

Restore Backup Options

One-Click Restore

Automated Restoration

  • Complete restoration: Restore entire site automatically
  • Database migration: Handle database differences
  • File replacement: Safe file replacement process
  • Rollback capability: Easy rollback if issues occur

Selective Restore

  • Database only: Restore just the database
  • Files only: Restore only WordPress files
  • Specific content: Restore specific posts, pages, or media
  • Incremental restore: Restore specific time periods

Manual Restore Process

Database Restoration

# Restore database from backup
mysql -h localhost -u username -p database_name < backup.sql

# Or using WP-CLI
wp db import backup.sql

# Update site URLs if domain changed
wp search-replace 'old-domain.com' 'new-domain.com'

File Restoration

# Restore WordPress files
tar -xzf wordpress-backup.tar.gz -C /path/to/wordpress

# Or using rsync for large sites
rsync -avz backup-files/ /path/to/wordpress/

# Fix file permissions
find /path/to/wordpress -type f -exec chmod 644 {} \;
find /path/to/wordpress -type d -exec chmod 755 {} \;

Configuration Restoration

// Restore WordPress configuration
define('DB_NAME', 'restored_database');
define('DB_USER', 'restored_user');
define('DB_PASSWORD', 'restored_password');
define('DB_HOST', 'localhost');

// Restore permalinks
global $wp_rewrite;
$wp_rewrite->flush_rules();

Hourly Backup Addon

Premium Backup Features

Real-Time Backup

  • Immediate backup: Backup on content changes
  • Version control: Multiple versions of content
  • Instant recovery: Restore to specific points in time
  • Continuous protection: Never lose recent changes

Hourly Scheduling

  • Custom intervals: Configure backup frequency
  • Smart scheduling: Avoid peak traffic periods
  • Resource management: Control backup resource usage
  • Priority queuing: Manage backup job priorities

Advanced Features

Point-in-Time Recovery

  • Granular recovery: Restore to exact moments
  • Change tracking: See what changed between backups
  • Selective recovery: Restore specific files or data
  • Preview capability: Preview backup contents before restore

Multi-Site Backup

  • Network-wide backup: Backup entire multisite network
  • Site-specific backup: Individual site backups
  • Cross-site restoration: Restore content between sites
  • Network migration: Move sites within network

Enterprise Features

Backup Encryption

  • AES-256 encryption: Military-grade encryption
  • Key management: Secure encryption key storage
  • Compliance ready: Meet regulatory requirements
  • Access control: Encrypted backup access control

Cloud Integration

  • Multi-cloud storage: Backup to multiple cloud providers
  • Geographic redundancy: Cross-region backup storage
  • Automatic failover: Switch providers if issues occur
  • Cost optimization: Optimize storage costs across providers

Backup Storage Options

Local Storage

  • Server storage: Store backups on same server
  • NAS/SAN: Network attached storage solutions
  • External drives: USB or external hard drives
  • Local network: Network storage devices

Cloud Storage

  • Amazon S3: Scalable cloud storage
  • Google Cloud Storage: Global storage network
  • Microsoft Azure: Enterprise cloud storage
  • Dropbox/Google Drive: Consumer cloud storage

Hybrid Storage

  • Local + Cloud: Combine local speed with cloud redundancy
  • Tiered storage: Hot/warm/cold storage tiers
  • Automated sync: Automatic cloud synchronization
  • Offline access: Access backups without internet

Backup Security

Encryption and Protection

Backup Encryption

// Encrypt backup files
function encrypt_backup_file($file_path, $encryption_key) {
    $file_contents = file_get_contents($file_path);
    $encrypted = openssl_encrypt($file_contents, 'AES-256-CBC', $encryption_key, 0, substr($encryption_key, 0, 16));
    file_put_contents($file_path . '.encrypted', $encrypted);
    unlink($file_path); // Remove unencrypted file
}

// Decrypt backup files
function decrypt_backup_file($encrypted_file_path, $encryption_key) {
    $encrypted_contents = file_get_contents($encrypted_file_path);
    $decrypted = openssl_decrypt($encrypted_contents, 'AES-256-CBC', $encryption_key, 0, substr($encryption_key, 0, 16));
    return $decrypted;
}

Access Control

  • User permissions: Control who can create/download backups
  • IP restrictions: Limit backup access to specific IPs
  • Authentication: Multi-factor authentication for backup access
  • Audit logging: Complete backup access logging

Backup Integrity

Checksum Verification

// Generate backup checksums
function generate_backup_checksum($backup_path) {
    $checksums = array();

    $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($backup_path));
    foreach ($iterator as $file) {
        if ($file->isFile()) {
            $relative_path = str_replace($backup_path . '/', '', $file->getPathname());
            $checksums[$relative_path] = hash_file('sha256', $file->getPathname());
        }
    }

    file_put_contents($backup_path . '/checksums.sha256', json_encode($checksums, JSON_PRETTY_PRINT));
    return $checksums;
}

// Verify backup integrity
function verify_backup_integrity($backup_path) {
    $checksums_file = $backup_path . '/checksums.sha256';

    if (!file_exists($checksums_file)) {
        return array('valid' => false, 'error' => 'Checksums file not found');
    }

    $stored_checksums = json_decode(file_get_contents($checksums_file), true);
    $current_checksums = generate_backup_checksum($backup_path);

    $differences = array();
    foreach ($stored_checksums as $file => $stored_hash) {
        if (!isset($current_checksums[$file])) {
            $differences[] = "Missing file: {$file}";
        } elseif ($current_checksums[$file] !== $stored_hash) {
            $differences[] = "Modified file: {$file}";
        }
    }

    return array(
        'valid' => empty($differences),
        'differences' => $differences
    );
}

Monitoring and Alerts

Backup Status Monitoring

Real-Time Monitoring

  • Backup progress: Live backup creation progress
  • Storage usage: Monitor backup storage consumption
  • Transfer speeds: Track backup upload/download speeds
  • Error detection: Immediate error notification

Automated Alerts

// Backup failure notifications
function send_backup_failure_alert($backup_type, $error_message) {
    $admin_email = get_option('admin_email');
    $site_name = get_bloginfo('name');

    $subject = "Backup Failed - {$site_name}";
    $message = "
    <h3>Backup Failure Alert</h3>
    <p><strong>Backup Type:</strong> {$backup_type}</p>
    <p><strong>Error:</strong> {$error_message}</p>
    <p><strong>Time:</strong> " . current_time('mysql') . "</p>
    <p>Please check the backup system and resolve the issue.</p>
    ";

    wp_mail($admin_email, $subject, $message, array('Content-Type: text/html; charset=UTF-8'));
}

// Success notifications
function send_backup_success_alert($backup_type, $backup_size, $duration) {
    $admin_email = get_option('admin_email');
    $site_name = get_bloginfo('name');

    $subject = "Backup Completed - {$site_name}";
    $message = "
    <h3>Backup Success Alert</h3>
    <p><strong>Backup Type:</strong> {$backup_type}</p>
    <p><strong>Size:</strong> " . size_format($backup_size) . "</p>
    <p><strong>Duration:</strong> {$duration} seconds</p>
    <p><strong>Time:</strong> " . current_time('mysql') . "</p>
    ";

    wp_mail($admin_email, $subject, $message, array('Content-Type: text/html; charset=UTF-8'));
}

Dashboard Integration

Backup Status Widget

// Add backup status to dashboard
function add_backup_status_widget() {
    wp_add_dashboard_widget(
        'backup_status_widget',
        'Backup Status',
        'display_backup_status_widget'
    );
}

function display_backup_status_widget() {
    $last_backup = get_option('last_backup_time');
    $backup_status = get_option('backup_status');
    $storage_used = get_option('backup_storage_used');

    echo '<div class="backup-status-widget">';
    echo '<p><strong>Last Backup:</strong> ' . ($last_backup ? date('M j, Y H:i', $last_backup) : 'Never') . '</p>';
    echo '<p><strong>Status:</strong> <span class="' . ($backup_status === 'success' ? 'success' : 'error') . '">' . ucfirst($backup_status) . '</span></p>';
    echo '<p><strong>Storage Used:</strong> ' . ($storage_used ? size_format($storage_used) : 'Unknown') . '</p>';

    if ($backup_status !== 'success') {
        echo '<p><a href="' . admin_url('admin.php?page=backup-settings') . '" class="button">Fix Backup Issues</a></p>';
    }

    echo '</div>';
}
add_action('wp_dashboard_setup', 'add_backup_status_widget');

Quick Actions

Best Practices

Backup Strategy

  1. 3-2-1 Rule: 3 copies, 2 media types, 1 offsite
  2. Regular Testing: Test backup restoration regularly
  3. Encryption: Encrypt sensitive backup data
  4. Documentation: Document backup procedures and locations
  5. Monitoring: Monitor backup success and integrity

Storage Management

  1. Retention Policies: Define how long to keep backups
  2. Compression: Compress backups to save space
  3. Deduplication: Remove duplicate data across backups
  4. Lifecycle Management: Move old backups to cheaper storage

Security Practices

  1. Access Control: Limit backup access to authorized users
  2. Encryption: Encrypt backups both in transit and at rest
  3. Integrity Checks: Regularly verify backup integrity
  4. Secure Storage: Use secure storage locations and methods

Comprehensive backup solutions for complete WordPress protection.

On this page