Search by

adachsoft / data-backup-symfony-bundle

Arkadiusz Adach

Symfony bundle for creating, listing, exporting, importing, and restoring data backup archives.

Package info

gitlab.com/a.adach/data-backup-symfony-bundle

Issues

pkg:composer/adachsoft/data-backup-symfony-bundle

Statistics

Installs: 4

Dependents: 0

Suggesters: 0

Stars: 0

v0.1.1 2026-11-25 14:47 UTC

This package is auto-updated.

Last update: 2026-11-25 13:48:27 UTC


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.

MethodPathPermissionDescription
GET/api/v1/backup/describebackup.readDescribe the local system and available data sources.
GET/api/v1/backup/archives?storage=NAMEbackup.readList archives from the selected or default storage.
POST/api/v1/backup/archivesbackup.runCreate an archive and return its reference and manifest.
GET/api/v1/backup/archives/{id}/download?storage=NAMEbackup.exportStream archive bytes as an attachment.
POST/api/v1/backup/archives/{id}/restore?storage=NAMEbackup.importRestore an archive using an ImportRequest JSON object.
POST/api/v1/backup/importbackup.importImport a multipart archive file.
DELETE/api/v1/backup/archives/{id}?storage=NAMEbackup.deleteDelete 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.