Skip to content
backup-managerPublic

About

Driver to seamlessly integrate the Backup Manager into Symfony applications.

Resources

Stars

118 stars

Watchers

6 watching

Forks

Repository files navigation

BackupManagerBundle

Tests Latest Version PHP Version Symfony Downloads License

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-v3 for AwsS3; 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 mysqldump and mysql command-line binaries
  • PostgreSQL support requires pg_dump and psql command-line binaries
  • Gzip support requires gzip and gunzip command-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.

About

Driver to seamlessly integrate the Backup Manager into Symfony applications.

Resources

Stars

118 stars

Watchers

6 watching

Forks

Releases

Packages

Used by

Contributors

Languages