How to backup roundcube mail

Roundcube is a popular web-based email client, and backing up your emails and settings is essential to ensure data security and availability. Here are the steps to backup Roundcube mail:

Method 1: Manual Backup using SQL and Filesystem

  1. Backup Roundcube database:
    • Connect to your MySQL database using a tool like phpMyAdmin or a command-line client.
    • Select the Roundcube database (usually named roundcubemail).
    • Click on the "Export" tab and choose the "Quick" method.
    • Select the tables you want to backup (e.g., users, messages, folders, etc.).
    • Choose a format (e.g., SQL) and a location to save the backup file.
  2. Backup Roundcube files:
    • Connect to your server using an FTP client or SFTP client.
    • Navigate to the Roundcube installation directory (usually /var/www/roundcubemail or similar).
    • Copy the following files and directories:
      • config.inc.php
      • plugins directory
      • skins directory
      • templates directory
    • Save the files and directories to a safe location.

Method 2: Automated Backup using Cron Jobs

  1. Create a backup script:
    • Create a new PHP file (e.g., backup_roundcube.php) in the Roundcube installation directory.
    • Add the following code to the file:
      
      <?php
      // Database connection settings
      $db_host = 'your_database_host';
      $db_username = 'your_database_username';
      $db_password = 'your_database_password';
      $db_name = 'your_database_name';

// Filesystem settings $backup_dir = '/path/to/backup/directory';

// Backup database $conn = new mysqli($db_host, $db_username, $db_password, $db_name); if ($conn->connect_error) { die("Connection failed: ". $conn->connect_error); } $sql = "SELECT * FROM users"; $result = $conn->query($sql); if (!$result) { die("Query failed: ". $conn->error); } while ($row = $result->fetch_assoc()) { // Backup user data $user_data = array(); $user_data[] = $row['username']; $user_data[] = $row['password']; //... file_put_contents($backup_dir. '/users/'. $row['username']. '.json', json_encode($user_data)); } $conn->close();

// Backup files $files = scandir($backup_dir. '/files'); foreach ($files as $file) { if (is_file($backup_dir. '/files/'. $file)) { copy($backup_dir. '/files/'. $file, $backup_dir. '/files/'. $file. '.bak'); } } ?>

2. **Schedule the backup script using Cron Jobs**:
    * Open your server's Cron Jobs configuration file (usually `/etc/crontab` or similar).
    * Add the following line to schedule the backup script to run daily at 2 AM:
```bash
0 2 * * * php /path/to/roundcube/backup_roundcube.php

Additional Tips