adachsoft / data-backup-symfony-bundle
Symfony bundle for creating, listing, exporting, importing, and restoring data backup archives.
Package info
gitlab.com/a.adach/data-backup-symfony-bundle
pkg:composer/adachsoft/data-backup-symfony-bundle
Requires
- php: ^8.3
- adachsoft/data-backup: ^0.2 || ^0.3
- adachsoft/data-backup-contracts: ^0.2
- nyholm/psr7: ^1.8
- symfony/clock: ^7.0 || ^8.0
- symfony/console: ^7.0 || ^8.0
- symfony/framework-bundle: ^7.0 || ^8.0
- symfony/http-foundation: ^7.0 || ^8.0
- symfony/routing: ^7.0 || ^8.0
- zircote/swagger-php: ^4.10 || ^5.0
Requires (Dev)
- adachsoft/php-code-style: ^0.7.4
- friendsofphp/php-cs-fixer: ^3.95
- phpstan/phpstan: ^2.3
- phpunit/phpunit: ^13.4
- rector/rector: ^2.9
- symfony/browser-kit: ^7.0 || ^8.0
- symfony/yaml: ^7.0 || ^8.0
- symplify/phpstan-rules: ^14.19
Suggests
Provides
None
Conflicts
None
Replaces
None
README
Symfony integration for adachsoft/data-backup that exposes archive operations through Symfony Console commands and an optional HTTP API.
Requirements
- PHP 8.3 or later
- Symfony FrameworkBundle 7 or 8
Installation and setup
Install the bundle and its core dependencies with Composer:
composer require adachsoft/data-backup-symfony-bundle
Register AdachSoft\\DataBackupSymfonyBundle\\DataBackupBundle in config/bundles.php if Symfony Flex has not registered it automatically. Configure at least a system identifier, an instance identifier, and one archive storage:
# config/packages/data_backup.yaml
data_backup:
system_id: my_application
instance_id: '%env(default:data_backup.instance:DATA_BACKUP_INSTANCE_ID)%'
default_storage: local
storages:
local:
type: filesystem
path: '%kernel.project_dir%/var/backups'
The filesystem storage is optional and requires adachsoft/data-backup-filesystem. You can instead configure a storage service implementing ArchiveStorageInterface. Register application data sources as Symfony services implementing DataSourceInterface; the bundle tags them automatically. See the usage examples for a complete setup outline.
Usage
Console commands
The bundle registers the following Symfony Console commands as services:
data-backup:run [--storage=NAME] [--source=ID]... [--label=key=value]...creates an archive in the selected storage (or the configured default) and prints its identifier and size.data-backup:list [--storage=NAME] [--json]lists stored archives with their creation time, scope, part count, size, and labels.data-backup:restore ARCHIVE_ID [--storage=NAME] [--mode=replace|merge] [--conflict=skip|overwrite|fail] [--missing-reference=fail|skip-record|keep] [--source=ID]... [--dry-run] [--force] [--json]restores an archive from storage.data-backup:export FILE [--source=ID]... [--label=key=value]...writes archive bytes to a file without using archive storage.data-backup:import FILE [--mode=replace|merge] [--conflict=skip|overwrite|fail] [--missing-reference=fail|skip-record|keep] [--source=ID]... [--dry-run] [--force] [--json]imports an archive file.
Import options default to merge, skip for conflicts, and fail for missing references. Repeat --source to select multiple data sources and --label to add multiple labels. Labels must use the key=value format.
A non-dry-run import or restore in replace mode requires --force in non-interactive environments. Interactive invocations ask for confirmation when --force is omitted. --dry-run validates the archive without importing data. Restore and import print a per-source report and issues list; pass --json for JSON output. The list command also supports --json.
Invalid option values return exit code 2. Failed operations, unsuccessful import reports, and unconfirmed destructive operations return exit code 1.
HTTP API
The HTTP API is disabled by default. Enable it in the application configuration:
data_backup:
http:
enabled: true
Import the bundle routes from the application's config/routes.yaml:
data_backup_http:
resource: '@DataBackupBundle/config/routes.yaml'
When data_backup.http.enabled is false, the imported endpoints return a JSON 404 response. The bundle sets _permission defaults on each route but does not enforce authentication or authorization; the application must enforce them in its firewall or access-control configuration.
| Method | Path | Permission | Description |
|---|---|---|---|
GET | /api/v1/backup/describe | backup.read | Describe the local system and available data sources. |
GET | /api/v1/backup/archives?storage=NAME | backup.read | List archives from the selected or default storage. |
POST | /api/v1/backup/archives | backup.run | Create an archive and return its reference and manifest. |
GET | /api/v1/backup/archives/{id}/download?storage=NAME | backup.export | Stream archive bytes as an attachment. |
POST | /api/v1/backup/archives/{id}/restore?storage=NAME | backup.import | Restore an archive using an ImportRequest JSON object. |
POST | /api/v1/backup/import | backup.import | Import a multipart archive file. |
DELETE | /api/v1/backup/archives/{id}?storage=NAME | backup.delete | Delete an archive. |
Archive creation accepts a JSON object with optional storage, sources and labels fields. Labels are a JSON object of string values:
{"storage":"local","sources":["accounts"],"labels":{"environment":"production"}}
Restore accepts the ImportRequest fields sources, mode, conflictPolicy, missingReferencePolicy and dryRun. Import options use the same JSON object in the multipart options field; the archive itself is the required multipart file field named archive. Missing import options use the console defaults (merge, skip, fail, and dryRun: false).
Client validation errors return HTTP 422 and a JSON body with error and message. Missing archives and storage names return HTTP 404 in the same format. Import and restore return HTTP 200 with the full report, including successful: false when an import report is unsuccessful.