Backup & Restore System
Relevant source files
The following files were used as context for generating this wiki page:
The Backup & Restore System in the Duplicator project provides a robust framework for managing SQLite database states. Its primary purpose is to ensure data integrity through automated and manual snapshots, allowing administrators to preserve, download, and revert database records without compromising the application's structure. Sources: app/models/admin/BackupManager.php, app/translations/en.json:115-118
The system is integrated into the administrative dashboard, specifically under the "Database Management" section. It handles portable backup directories across different operating systems (Windows, Linux via AppImage, and macOS) to ensure that snapshots are stored in persistent, writable locations. Sources: app/models/admin/BackupManager.php:177-248, app/view/admin.bdd.html.php:336-391
System Architecture
The backup system is centered around the BackupManager class, which interacts directly with the filesystem to manipulate .sqlite files. It acts as a service layer called by the administrative controllers to perform file-level operations rather than SQL-level dumps.
Key Components
| Component | Description | File Path |
|---|---|---|
BackupManager | Core logic for creating, restoring, and deleting snapshots. | app/models/admin/BackupManager.php |
SQLiteDatabaseManager | Manages active database switching and structure initialization. | app/models/admin.php:164-166 |
admin.bdd.html.php | User interface for triggering backup actions and managing files. | app/view/admin.bdd.html.php |
setup.html.php | Handles initial database imports during system configuration. | app/view/setup.html.php:79-115 |
Sources: app/models/admin/BackupManager.php:8, app/models/admin.php:164, app/view/admin.bdd.html.php:1
Data Flow for Manual Backup
The following diagram illustrates the process of creating a manual backup from the administrative interface.
Core Functionalities
Backup Creation
Backups are created by copying the active SQLite database file to a designated backup folder. Filenames are generated using a timestamp (Y-m-d_H-i-s) and the original database name. If a custom name is provided, it is prepended to the timestamp. Sources: app/models/admin/BackupManager.php:78-81
Restoration and Safety Backups
When a user restores a backup, the system performs a Safety Backup of the current active database before overwriting it. This safety file is named with the .safety_ prefix and a timestamp, ensuring that unintended restorations can be reverted. Sources: app/models/admin/BackupManager.php:109-113, app/tests/Feature/AdminBackupManagerTest.php:41-52
Portable Directory Resolution
The system dynamically resolves backup directories based on the environment:
- AppImage/Linux: Uses
~/.config/dupli-electron/sauvegarde. - Windows: Uses
%APPDATA%\dupli-electron\sauvegarde. - Fallback: If primary directories are read-only, it reverts to system temporary directories.
Sources: app/models/admin/BackupManager.php:189-231
API and Operations
BackupManager Methods
| Method | Parameters | Return Type | Description |
|---|---|---|---|
createBackup | $backup_name (string) | array | Copies active DB to the backup dir. |
restoreBackup | $backup_file (string) | array | Overwrites active DB with a backup. |
deleteBackup | $backup_file (string) | array | Removes a backup file from storage. |
getBackupsList | None | array | Returns sorted list of backups with size/date. |
uploadBackup | $_FILES object | array | Validates and moves uploaded .sqlite files. |
Sources: app/models/admin/BackupManager.php:59-174
Implementation Example: File Deletion
public function deleteBackup($backup_file) {
$result = array();
try {
$filepath = $this->backup_dir . $backup_file;
if (!file_exists($filepath)) {
$result['error'] = "Backup file not found";
return $result;
}
if (unlink($filepath)) {
$result['success'] = "Backup deleted successfully";
}
} catch (Exception $e) {
$result['error'] = $e->getMessage();
}
return $result;
}
Sources: app/models/admin/BackupManager.php:133-155
Administrative Interface
The admin.bdd.html.php view provides the frontend for these operations. It allows users to:
- View List: Displays backups sorted by date (newest first). Sources: app/view/admin.bdd.html.php:364-391
- Upload: Supports uploading external
.sqlitefiles up to 50MB. Sources: app/view/admin.bdd.html.php:336-352 - Download: Provides a direct link to download stored backups. Sources: app/view/admin.bdd.html.php:382
Summary
The Backup & Restore System is a critical reliability feature of the Duplicator application. By utilizing file-level snapshots, safety backups during restoration, and environment-aware storage paths, it provides a portable and secure way to manage the SQLite data layer across multiple platforms. Sources: app/models/admin/BackupManager.php, app/view/admin.bdd.html.php