Search by

phil / backup-bundle

philSocolin

phil/backup in Symfony: database and media backups from configuration, encrypted and rotated, restored behind a confirmation guard, and tested by restoring.

Package info

github.com/parler-haut-interagir-librement/backup-bundle

Homepage

Type:symfony-bundle

pkg:composer/phil/backup-bundle

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

0.1.3-alpha 2026-12-01 22:00 UTC

This package is auto-updated.

Last update: 2026-12-02 03:13:53 UTC


README

Back a Symfony application's database and media files up from its configuration, restore them behind a guard, and test that they restore.

phil/backup-bundle puts phil/backup in a Symfony application. It reads the Doctrine DBAL connection to choose the client — SQLite, MySQL, MariaDB or PostgreSQL — and to give it the credentials, which never reach a command line. It backs the media directories up beside the database, encrypts every file with a key read from the environment, and rotates the backups after each one. Three commands do the work: phil:backup:create, phil:backup:restore and phil:backup:verify, each holding an exclusive lock of the backup directory, so that a rotation never removes a set another command is writing or testing; a fourth, phil:backup:monitor, tells the monitoring whether the latest backup is recent enough.

A restore is a decision taken twice. In production it is refused unless PHIL_BACKUP_ALLOW_PRODUCTION_RESTORE holds the name of the database; everywhere it needs --confirm and the database's name typed again, asked for when the console is interactive. The current content is then backed up, labelled before-restore, and the restore starts only once that backup is written; the latest three of these are kept. Media files added since the backup are left, unless --prune removes them. A key is required unless allow_unencrypted: true is set. phil:backup:verify restores a backup into a copy — a temporary file for SQLite, a scratch database for a server — and checks it there, without touching the database.

It is for the developers and operators of a Symfony application who need backups they can trust and restores they cannot run by accident. It does not schedule the backups or copy them off the machine: the application's scheduler and storage do, and its monitoring reads phil:backup:monitor; see commands.md.

It is a Symfony bundle on phil/backup, the Console component, Doctrine DBAL, Symfony Lock and Symfony Process, and needs the database's client tools where the commands run.

Status

Area State
PhilBackupBundle: connection, directory, binaries, timeout, warn_after, grace_period, key, allow_unencrypted, media, rotation, restore, lock, monitor, verify Implemented and tested
DatabaseClients: the client of a DBAL connection, without connecting Implemented and tested
ProcessCommandRunner: Symfony Process, no shell, a warning and an event for a slow tool, an optional time limit Implemented and tested
phil:backup:create, phil:backup:restore, phil:backup:verify Implemented and tested on SQLite with the real sqlite3; MySQL, MariaDB and PostgreSQL by their command lines
BackupLock: one exclusive lock per directory, over Symfony Lock, held by those three commands Implemented and tested
phil:backup:monitor: the age of the latest backup against a threshold in hours Implemented and tested

Documentation

  • Installation — requirements, installing with Composer, registering the bundle, the client tools, a first key.
  • Configuration — every key of phil_backup, its default and effect, the services it wires, and each build-time error.
  • Commands — creating, restoring, testing and monitoring backups, their options and messages, the lock, scheduling, and copying a production database to work on, with the retention of an anonymized copy.
  • Restore protection — production, the confirmation, the name typed again, and the backup taken first.
  • Extension points — the services you can rely on, another runner or client.
  • Testing — how the bundle is tested, and how to test your configuration.
  • API reference — every type of the bundle, with its role.

Quick start

composer require phil/backup-bundle:^0.1@dev
# config/packages/phil_backup.yaml
phil_backup:
    key: '%env(PHIL_BACKUP_KEY)%'
    media: { uploads: '%kernel.project_dir%/public/uploads' }
    rotation: { last: 3, daily: 7, weekly: 4, monthly: 12 }
bin/console phil:backup:create
bin/console phil:backup:verify
bin/console phil:backup:restore --confirm            # asks for the database's name

Requirements

PHP 8.5 or later, phil/backup, doctrine/dbal 4.5, and symfony/config, symfony/console, symfony/dependency-injection and symfony/process 8.2.

Contributing

Contributions are welcome on the PHIL monorepo: read the contribution guide and the code of conduct. Report a vulnerability privately, as the security policy explains, never in a public issue.

License

MIT, © Philippe Gamache, doing business as Le Gnome Archiviste; a Parler Haut Interagir Librement project. See LICENSE.