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.
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/symfonyThis command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.
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.
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],
// ...
];# 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: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.sqlRestore 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 gzipThis package does not allow you to backup from one database type and restore to another. A MySQL dump is not compatible with PostgreSQL.
- 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
| 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 |
See Changelog.md.