backup-manager / symfony
Database backup manager bundle for Symfony: back up and restore MySQL and PostgreSQL to S3, Google Cloud Storage, Dropbox, FTP, SFTP, WebDAV and more.
Package info
github.com/backup-manager/symfony
Type:symfony-bundle
pkg:composer/backup-manager/symfony
Requires
- php: ^8.2
- backup-manager/backup-manager: ^4.1.1
- league/flysystem: ^3.35.3
- nyholm/dsn: ^2.0
- symfony/config: ^6.4.50 || ^7.4.23 || ^8.1.11
- symfony/console: ^6.4 || ^7.4 || ^8.1
- symfony/dependency-injection: ^6.4 || ^7.4 || ^8.1
- symfony/filesystem: ^6.4.50 || ^7.4.23 || ^8.1.11
- symfony/framework-bundle: ^6.4.49 || ^7.4.23 || ^8.1.11
- symfony/http-kernel: ^6.4.50 || ^7.4.23 || ^8.1.11
- symfony/process: ^6.4.33 || ^7.4.5 || ^8.1
- symfony/yaml: ^6.4.50 || ^7.4.23 || ^8.1.11
Requires (Dev)
- matthiasnoback/symfony-config-test: ^5.1 || ^6.0
- matthiasnoback/symfony-dependency-injection-test: ^5.1 || ^6.0
- phpunit/phpunit: ^11.5.50 || ^12.5.8
Suggests
- league/flysystem-async-aws-s3: AsyncAwsS3 storage type
- league/flysystem-aws-s3-v3: AwsS3 storage type
- league/flysystem-ftp: Ftp storage type
- league/flysystem-google-cloud-storage: Gcs storage type
- league/flysystem-sftp-v3: Sftp storage type
- league/flysystem-webdav: Webdav storage type
- spatie/flysystem-dropbox: Dropbox storage type
Provides
None
Conflicts
None
Replaces
None
README
Back up and restore MySQL and PostgreSQL databases from your Symfony application to S3, Google Cloud Storage, Dropbox, FTP, SFTP, WebDAV or local disk.
This package pulls in the framework agnostic Backup Manager and provides seamless integration with Symfony.
Installation
Step 1: Download the Bundle
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
$ composer require backup-manager/symfony
This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.
Step 2 (with Flex): Enable the Bundle
You do not need to do anything more. The bundle is enabled automatically and
you have some nice default config in config/packages/bm_backup_manager.yml.
Step 2 (no Flex): Enable the Bundle
If you are not using Symfony Flex, you need to enable the bundle by adding it to
the list of registered bundles in the app/AppKernel.php file of your project.
// config/bundles.php return [ BM\BackupManagerBundle\BMBackupManagerBundle::class => ['all' => true], // ... ];
Step 3: Configure your databases and filesystems
# config/packages/bm_backup_manager.yml bm_backup_manager: database: development: type: mysql host: localhost port: 3306 user: root pass: password database: test ignoreTables: ['foo', 'bar'] # MySQL only, all optional: # onlyTables: ['users', 'orders'] # dump only these tables # singleTransaction: true # --single-transaction (InnoDB) # ssl: true # --ssl # columnStatistics: false # --column-statistics=0 (MySQL 8 mysqldump, older servers) # socket: /run/mysqld/mysqld.sock # instead of host and port # extraParams: '--max-allowed-packet=64M' # MySQL only; ignored for PostgreSQL # If DSN is specified, it will override other values. User and # password must be url-encoded (e.g. "p@ss" as "p%40ss"). dsn: 'mysql://root:root_pass@127.0.0.1:3306/test_db' production: type: postgresql host: localhost port: 5432 user: postgres pass: password database: test # You could also use a environment variable dsn: '%env(resolve:DATABASE_URL)%' storage: local: type: Local root: /path/to/working/directory s3: type: AwsS3 key: secret: region: us-east-1 version: latest bucket: root: # S3-compatible services (DigitalOcean Spaces, MinIO, ...) also set # endpoint: and use_path_style_endpoint: async_s3: type: AsyncAwsS3 # async-aws instead of the AWS SDK (Flysystem 2/3) key: secret: region: us-east-1 bucket: root: gcs: type: Gcs project: keyFilePath: bucket: prefix: dropbox: type: Dropbox token: root: webdav: type: Webdav baseUri: userName: password: prefix: ftp: type: Ftp host: username: password: root: port: 21 passive: true ssl: true timeout: 30 sftp: type: Sftp host: username: password: root: port: 22 timeout: 10 privateKey:
Usage
To backup from any configured database.
Backup the development database to Amazon S3. The S3 backup path will be test/backup.sql.gz in the end, when gzip is done with it.
class Foo { private $backupManager; public function __construct(BackupManager $backupManager) { $this->backupManager = $backupManager; } public function bar() { $this->backupManager->makeBackup()->run('development', [new Destination('s3', 'test/backup.sql')], 'gzip'); } }
Or with a command:
php bin/console backup-manager:backup development s3 -c gzip --filename test/backup.sql
To restore from any configured filesystem.
Restore the database file test/backup.sql.gz from Amazon S3 to the development database.
class Foo { private $backupManager; public function __construct(BackupManager $backupManager) { $this->backupManager = $backupManager; } public function bar() { $this->backupManager->makeRestore()->run('s3', 'test/backup.sql.gz', 'development', 'gzip'); } }
Or with a command:
php bin/console backup-manager:restore development s3 test/backup.sql.gz -c gzip
This package does not allow you to backup from one database type and restore to another. A MySQL dump is not compatible with PostgreSQL.
Requirements
- PHP 8.2+
- Symfony 6.4, 7.4 or 8.1+, at releases patched for known security advisories. CI tests each. For Symfony 5.4 or PHP 7.4–8.1 use version 3.x.
- The Flysystem adapter package for each storage type you use, for example
league/flysystem-aws-s3-v3forAwsS3; see the core adapter table. A missing package is reported, with the package name, when the storage is used. - Upgrading from 3.x: see UPGRADE.md.
- MySQL support requires
mysqldumpandmysqlcommand-line binaries - PostgreSQL support requires
pg_dumpandpsqlcommand-line binaries - Gzip support requires
gzipandgunzipcommand-line binaries
Supported versions
| Version | Symfony | PHP | Core library | Support |
|---|---|---|---|---|
| 4.x | 6.4, 7.4, 8.1+ | 8.2+ | 4.x | active |
| 3.x | 5.4–8.1+ | 7.4+ | 3.x | security fixes until 2027-12-31 |
Changelog
See Changelog.md.