This package provides a framework-agnostic database backup manager for dumping to and restoring databases from S3, Dropbox, FTP, SFTP, and Rackspace Cloud

Overview

Database Backup Manager

Latest Stable Version License Build Status Coverage Status Total Downloads

This package provides a framework-agnostic database backup manager for dumping to and restoring databases from S3, Dropbox, FTP, SFTP, and Rackspace Cloud.

  • use version 2+ for >=PHP 7.3
  • use version 1 for

Watch a video tour showing the Laravel driver in action to give you an idea what is possible.

Table of Contents

Quick and Dirty

Configure your databases.

// config/database.php
'development' => [
    'type' => 'mysql',
    'host' => 'localhost',
    'port' => '3306',
    'user' => 'root',
    'pass' => 'password',
    'database' => 'test',
    // If singleTransaction is set to true, the --single-transcation flag will be set.
    // This is useful on transactional databases like InnoDB.
    // http://dev.mysql.com/doc/refman/5.7/en/mysqldump.html#option_mysqldump_single-transaction
    'singleTransaction' => false,
    // Do not dump the given tables
    // Set only table names, without database name
    // Example: ['table1', 'table2']
    // http://dev.mysql.com/doc/refman/5.7/en/mysqldump.html#option_mysqldump_ignore-table
    'ignoreTables' => [],
    // using ssl to connect to your database - active ssl-support (mysql only):
    'ssl'=>false,
    // add additional options to dump-command (like '--max-allowed-packet')
    'extraParams'=>null,
],
'production' => [
    'type' => 'postgresql',
    'host' => 'localhost',
    'port' => '5432',
    'user' => 'postgres',
    'pass' => 'password',
    'database' => 'test',
],

Configure your filesystems.

// config/storage.php
'local' => [
    'type' => 'Local',
    'root' => '/path/to/working/directory',
],
's3' => [
    'type' => 'AwsS3',
    'key'    => '',
    'secret' => '',
    'region' => 'us-east-1',
    'version' => 'latest',
    'bucket' => '',
    'root'   => '',
    'use_path_style_endpoint' => false,
],
'b2' => [
    'type' => 'B2',
    'key'    => '',
    'accountId' => '',
    'bucket' => '',
],
'gcs' => [
    'type' => 'Gcs',
    'key'    => '',
    'secret' => '',
    'version' => 'latest',
    'bucket' => '',
    'root'   => '',
],
'rackspace' => [
    'type' => 'Rackspace',
    'username' => '',
    'key' => '',
    'container' => '',
    'zone' => '',
    'root' => '',
],
'dropbox' => [
    'type' => 'DropboxV2',
    'token' => '',
    'key' => '',
    'secret' => '',
    'app' => '',
    'root' => '',
],
'ftp' => [
    'type' => 'Ftp',
    'host' => '',
    'username' => '',
    'password' => '',
    'root' => '',
    'port' => 21,
    'passive' => true,
    'ssl' => true,
    'timeout' => 30,
],
'sftp' => [
    'type' => 'Sftp',
    'host' => '',
    'username' => '',
    'password' => '',
    'root' => '',
    'port' => 21,
    'timeout' => 10,
    'privateKey' => '',
],
'flysystem' => [
    'type' => 'Flysystem',
    'name' => 's3_backup',
    //'prefix' => 'upload',
],
'doSpaces' => [
    'type' => 'AwsS3',
    'key' => '',
    'secret' => '',
    'region' => '',
    'bucket' => '',
    'root' => '',
    'endpoint' => '',
    'use_path_style_endpoint' => false,
],
'webdav' => [
    'type' => 'Webdav',
    'baseUri' => 'http://myserver.com',
    'userName' => '',
    'password' => '',
    'prefix' => '',
],

Backup to / restore 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.

use BackupManager\Filesystems\Destination;

$manager = require 'bootstrap.php';
$manager->makeBackup()->run('development', [new Destination('s3', 'test/backup.sql')], 'gzip');

Backup to / restore from any configured filesystem.

Restore the database file test/backup.sql.gz from Amazon S3 to the development database.

$manager = require 'bootstrap.php';
$manager->makeRestore()->run('s3', 'test/backup.sql.gz', 'development', '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 5.5
  • 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

Installation

Composer

Run the following to include this via Composer

composer require backup-manager/backup-manager

Then, you'll need to select the appropriate packages for the adapters that you want to use.

# to support s3
composer require league/flysystem-aws-s3-v3

# to support b2
composer require mhetreramesh/flysystem-backblaze

# to support google cs
composer require league/flysystem-aws-s3-v2

# to install the preferred dropbox v2 driver
composer required spatie/flysystem-dropbox

# to install legacy dropbox v2 driver
composer require srmklive/flysystem-dropbox-v2

# to support rackspace
composer require league/flysystem-rackspace

# to support sftp
composer require league/flysystem-sftp

# to support webdav (supported by owncloud nad many other)
composer require league/flysystem-webdav

Usage

Once installed, the package must be bootstrapped (initial configuration) before it can be used.

We've provided a native PHP example here.

The required bootstrapping can be found in the example here.

Contribution Guidelines

We recommend using the vagrant configuration supplied with this package for development and contribution. Simply install VirtualBox, Vagrant, and Ansible then run vagrant up in the root folder. A virtualmachine specifically designed for development of the package will be built and launched for you.

When contributing please consider the following guidelines:

  • Code style is PSR-2
    • Interfaces should NOT be suffixed with Interface, Traits should NOT be suffixed with Trait.
  • All methods and classes must contain docblocks.
  • Ensure that you submit tests that have minimal 100% coverage. Given the project's simplicity it just makes sense.
  • When planning a pull-request to add new functionality, it may be wise to submit a proposal to ensure compatibility with the project's goals.

Maintainers

This package is maintained by Shawn McCool and you!

Backwards Compatibility Breaks

3.0

Remove support for symfony 2. Specifically symfony/process versions < 3.x

License

This package is licensed under the MIT license. Go wild.

Comments
  • Could not find configuration for connection

    Could not find configuration for connection

    Hi

    Have been using this great code for a while but suddenly I have this error, and the backups fail?

    [BigName\BackupManager\Config\ConfigNotFoundForConnection]
    Could not find configuration for connection local-sitename

    [ 'type' => 'mysql', 'host' => 'localhost', 'port' => '3306', 'user' => 'root', 'pass' => 'secret', 'database' => 'mydatabase', ], ]; $now = strftime("%Y_%m_%d", strtotime("now")); $manager = App::make('BigName\BackupManager\Manager'); $manager->makeBackup()->run( 'local-sitename', 'local', $now.'_mybck.sql', 'gzip' ); Trying to run this from my terminal php artisan nightly --env=local-sitename
    opened by johannesfosseus 26
  • FileExistsException when restoring database

    FileExistsException when restoring database

    When I run php artisan db:restore, I get a FileExistsException at the end:

    [League\Flysystem\FileExistsException] File already exists at path: development__2014-07-24__12-22-58.sql.gz

    Curiously, I also get asked "From which database connection you want to dump?" (I answer mysql, which is the only option).

    opened by MikeHopley 22
  • Add support for encryption

    Add support for encryption

    Hi guys,

    Would it be possible to add an encryptor that encrypts the compressed package? Might be an idea to add an encryption interface to allow multiple encryption types (openssl/gpg).

    I could try to send a PR if this sounds good for you guys, but realistically I won't have time the coming weeks.

    Thanks!

    enhancement 
    opened by RickvdP 16
  • Allow exporting database dump to multiple locations

    Allow exporting database dump to multiple locations

    Hi,

    I've made some modifications to BackupProcedure in order to allow exporting database dump to multiple locations. In our case, we store locally last 10 database dumps for easy and fast restoring, and upload to remote S3 as persistent backup. With the original implementation, we were forced to execute the database dump twice to upload to both locations.

    With this changes, following the example you include in the source code, you can export to a single location using the same run method, or using execute() in the following way:

    $manager = require 'bootstrap.php';
    $processor = $manager->makeBackup();
    $processor->addDestinationFileSystem('local');
    $processor->setDatabase('database');
    $processor->setDestinationPath('dump.sql');
    $processor->setCompression('gzip');
    $processor->execute();
    

    For exporting to local filesystem and Amazon S3 simultaneously, for instance:

    $manager = require 'bootstrap.php';
    $processor = $manager->makeBackup();
    $processor->addDestinationFileSystem('local');
    $processor->addDestinationFileSystem('s3');
    $processor->setDatabase('database');
    $processor->setDestinationPath('dump.sql');
    $processor->setCompression('gzip');
    $processor->execute();
    

    I hope you'll find this changes useful too.

    Best regards and congratulations for this great piece of work!

    opened by obokaman-com 12
  • Laravel 4.2 error

    Laravel 4.2 error

    Hi

    I get the following error trying to use backup-manager and Laravel 4.2

    Access level to BigName\BackupManager\Integrations\Laravel\BaseCommand::table() must be public

    Full error from the terminal gere.

    {"error":{"type":"Symfony\Component\Debug\Exception\FatalErrorException","message":"Access level to BigName\BackupManager\Integrations\Laravel\BaseCommand::table() must be public (as in class Illuminate\Console\Command)","file":"/Users/johannes.fosseus/Documents/vagrants/poetfreak/vendor/heybigname/backup-manager/src/Integrations/Laravel/BaseCommand.php","line":46}}

    Script php artisan clear-compiled handling the post-update-cmd event returned with an error

    BR // johannes

    opened by johannesfosseus 12
  • Packagist Name

    Packagist Name

    @GrahamCampbell is it possible to somehow migrate to the packagist package backup-manager/backup-manager instead of heybigname/backup-manager without breaking everyone's installs?

    I don't care if we lose install statistics or anything else.

    opened by ShawnMcCool 11
  • What if Server Space is full or DB is Down

    What if Server Space is full or DB is Down

    hi,

    I have set up a cron job, for DB backup and storing in project directory.

    I need to know, what will happen: 1) - If Server space is full. 2) - DB is down.

    How i will come to know whether the backup is success or failure.?

    Secondly - how to add labels to issue.? eg- this is question. how to tag with question label.?

    enhancement 
    opened by ghost 9
  • Laravel5 integration fixed

    Laravel5 integration fixed

    Hey @ShawnMcCool and @mitchellvanw ,

    I just completed my fix and contribution to getting the backup-manager working in Laravel 5. I am working on a plugin for October CMS (which is all Laravel 5 based). So, now this package should be good to go to work for the Laravel 5.

    You can see that I also updated the readme to support Laravel 4 and 5. In Laravel 5 Taylor changed how packages are registered and published within the boot method. In addition, the config files are published with a new command in L5 called "vendor:publish".

    I hope you accept this and merge and release into your master. Let me know how this goes!

    Thanks, Adam

    opened by cmosguy 9
  • Permission Denied error

    Permission Denied error

    I copied the example provided but getting the error below. Have given 777 permission.

    \nFatal error: Uncaught exception 'BackupManager\ShellProcessing\ShellProcessFailed' with message 'sh: 1: cannot create /567d3a4664faa: Permission denied \n' in /usr/share/nginx/html/htdocs/dbback/vendor/backup-manager/backup-manager/src/ShellProcessing/ShellProcessor.php:35\nStack trace:\n#0 /usr/share/ngin x/html/htdocs/dbback/vendor/backup-manager/backup-manager/src/Tasks/Database/DumpDatabase.php(35): BackupManager\ShellProcessing\ShellProcessor->process( )\n#1 /usr/share/nginx/html/htdocs/dbback/vendor/backup-manager/backup-manager/src/Procedures/Sequence.php(27): BackupManager\Tasks\Database\DumpDatabas e->execute()\n#2 /usr/share/nginx/html/htdocs/dbback/vendor/backup-manager/backup-manager/src/Procedures/BackupProcedure.php(57): BackupManager\Procedures \Sequence->execute()\n#3 /usr/share/nginx/html/htdocs/dbback/backup.php(3): BackupManager\Procedures\BackupProcedure->run()\n#4 {main}

    opened by subzero355 8
  • Rackspace Error

    Rackspace Error

    You've filled in the following answers: Database: production Destination: rackspace Destination Path: //2014-06-03_12:16:46.sql Compression: gzip

    Are these correct? [y/n]y PHP Fatal error: Class 'OpenCloud\OpenStack' not found in /home/vagrant/sites/MiMejorPlan/vendor/heybigname/backup-manager/src/Filesystems/RackspaceFilesystem.php on line 30 PHP Stack trace: PHP 1. {main}() /home/vagrant/sites/MiMejorPlan/artisan:0 PHP 2. Symfony\Component\Console\Application->run() /home/vagrant/sites/MiMejorPlan/artisan:59 PHP 3. Symfony\Component\Console\Application->doRun() /home/vagrant/sites/MiMejorPlan/vendor/symfony/console/Symfony/Component/Console/Application.php:121 PHP 4. Symfony\Component\Console\Application->doRunCommand() /home/vagrant/sites/MiMejorPlan/vendor/symfony/console/Symfony/Component/Console/Application.php:191 PHP 5. Illuminate\Console\Command->run() /home/vagrant/sites/MiMejorPlan/vendor/symfony/console/Symfony/Component/Console/Application.php:885 PHP 6. Symfony\Component\Console\Command\Command->run() /home/vagrant/sites/MiMejorPlan/vendor/laravel/framework/src/Illuminate/Console/Command.php:96 PHP 7. Illuminate\Console\Command->execute() /home/vagrant/sites/MiMejorPlan/vendor/symfony/console/Symfony/Component/Console/Command/Command.php:241 PHP 8. BigName\BackupManager\Integrations\Laravel\DbBackupCommand->fire() /home/vagrant/sites/MiMejorPlan/vendor/laravel/framework/src/Illuminate/Console/Command.php:108 PHP 9. BigName\BackupManager\Procedures\BackupProcedure->run() /home/vagrant/sites/MiMejorPlan/vendor/heybigname/backup-manager/src/Integrations/Laravel/DbBackupCommand.php:94 PHP 10. BigName\BackupManager\Filesystems\FilesystemProvider->get() /home/vagrant/sites/MiMejorPlan/vendor/heybigname/backup-manager/src/Procedures/BackupProcedure.php:55 PHP 11. BigName\BackupManager\Filesystems\RackspaceFilesystem->get() /home/vagrant/sites/MiMejorPlan/vendor/heybigname/backup-manager/src/Filesystems/FilesystemProvider.php:47 {"error":{"type":"Symfony\Component\Debug\Exception\FatalErrorException","message":"Class 'OpenCloud\OpenStack' not found","file":"/home/vagrant/sites/MiMejorPlan/vendor/heybigname/backup-manager/src/Filesystems/RackspaceFilesystem.php","line":30}}vagrant@homestead:~/sites/MiMejorPlan$

    opened by j0an 8
  • Dropbox problem when overwriting files

    Dropbox problem when overwriting files

    Hi,

    I'm trying to save my backups in dropbox but when run the backup the second time I get this error:

    [League\Flysystem\FileExistsException]         
    File already exists at path: database.sql.gz  
    

    Is there a way to set that the file must be overwritten in the dropbox folder?

    opened by khrizt 7
  • Class

    Class "Aws\S3\S3Client" not found

    I can't use AWS S3 Bucket.

    Type: Error
    
    Message: Class "Aws\S3\S3Client" not found
    
    Filename: /var/www/html/modules/backup/vendor/backup-manager/backup-manager/src/Filesystems/Awss3Filesystem.php
    
    Line Number: 28
    
    Backtrace:
    
    File: /var/www/html/modules/backup/vendor/backup-manager/backup-manager/src/Filesystems/FilesystemProvider.php
    Line: 47
    Function: get
    
    File: /var/www/html/modules/backup/vendor/backup-manager/backup-manager/src/Procedures/BackupProcedure.php
    Line: 55
    Function: get
    

    In composer.lock file I see "league/flysystem-aws-s3-v3": "~1.0", which means its using very old version of that file. Can you check from your end if it's working or not.

    opened by faizananwerali 0
  • Fatal error after updating to 3.1.0

    Fatal error after updating to 3.1.0

    PHP Fatal error:  Uncaught Error: Class 'League\Flysystem\Adapter\Local' not found in [...]/vendor/backup-manager/backup-manager/src/Filesystems/LocalFilesystem.php:28
    

    This class no longer exists in league/flysystem versions 2 & 3

    opened by Jelle-S 1
  • Multiple databases

    Multiple databases

    Hi is it possible to backup multiple databases from the same backup.php file? I would like to run only one cron job and not multiple for each database

    opened by vince844 0
  • Using Command returns 0 on failed upload

    Using Command returns 0 on failed upload

    Hey

    First of all, thank you for building this lib. I really like it and the possibilities with it.

    I use this library within a symfony project. I run it on command-line like this, php bin/console --env=prod backup-manager:backup development dropbox -c gzip --filename "$(date +'%Y%m%d-%H%M%S')-backup.sql"

    This command returns 0 indifferent if dropbox upload worked or not.

    I figured out that this is the case because of not using the result writeStream method.

    I found it in TransferFile.php

        /**
         * @throws FileExistsException
         * @throws FileNotFoundException
         */
        public function execute()
        {
            $this->destinationFilesystem->writeStream(
                $this->destinationPath,
                $this->sourceFilesystem->readStream($this->sourcePath)
            );
        }
    

    Would it be possible, in the close future, to return the failing of writeStream up to the surface?

    For it would be indifferent whether the Exception is thrown to the surface or at least the command would fail.

    Background: I'd like to use the command together with healthchecks.io and know when the command finished successfully. If the command would fail I could get automatically be notified.

    If you have any further question please don't hesitate to ask.

    opened by DjThossi 0
  • Add change logs

    Add change logs

    I suggest that we should start using a change log whenever we release new versions.

    Im currently trying to figure out what is the breaking changes between 1.x, 2.x and 3.x.

    opened by Nyholm 0
Releases(3.1.0)
  • 3.1.0(Jul 5, 2022)

    What's Changed

    • Fixed broken master by @Nyholm in https://github.com/backup-manager/backup-manager/pull/165
    • Add PHP 8.0 support to composer.json by @benr77 in https://github.com/backup-manager/backup-manager/pull/176
    • Make sure we run CI by @Nyholm in https://github.com/backup-manager/backup-manager/pull/181
    • Apply code style rules by @Nyholm in https://github.com/backup-manager/backup-manager/pull/182
    • Fixing tests and make CI green by @Nyholm in https://github.com/backup-manager/backup-manager/pull/183

    New Contributors

    • @benr77 made their first contribution in https://github.com/backup-manager/backup-manager/pull/176

    Full Changelog: https://github.com/backup-manager/backup-manager/compare/3.0.1...3.1.0

    Source code(tar.gz)
    Source code(zip)
  • 3.0.1(Jul 5, 2022)

  • 1.1.1(Feb 5, 2016)

Owner
Backup Manager
A framework agnostic database backup manager with user-definable procedures and support for S3, Dropbox, FTP, SFTP, and more.
Backup Manager
A mysql database backup package for laravel

Laravel Database Backup Package This package will take backup your mysql database automatically via cron job. Installing laravel-backup The recommende

Mahedi Hasan Durjoy 20 Jun 23, 2021
Driver to seamlessly integrate the Backup Manager into Laravel applications.

Laravel Driver for the Database Backup Manager This package pulls in the framework agnostic Backup Manager and provides seamless integration with Lara

Backup Manager 636 Dec 30, 2022
A package to backup your Laravel app

A modern backup solution for Laravel apps This Laravel package creates a backup of your application. The backup is a zip file that contains all files

Spatie 5.1k Jan 1, 2023
[Package] Multi-tenant Database Schema Manager for Laravel

Multi-tenant Database Schema Manager for Laravel Tenanti allow you to manage multi-tenant data schema and migration manager for your Laravel applicati

Orchestra Platform 580 Dec 5, 2022
phpMyFAQ - Open Source FAQ web application for PHP and MySQL, PostgreSQL and other databases

phpMyFAQ 3.1 What is phpMyFAQ? phpMyFAQ is a multilingual, completely database-driven FAQ-system. It supports various databases to store all data, PHP

Thorsten Rinne 547 Dec 27, 2022
A Symfony application for managing and automating regular backups of MySQL databases.

DbSaver DbSaver is an application written by Bastien LOUGHIN allowing you to make automatic daily backups (and manual backups) for your MySQL database

Bastien 35 Nov 11, 2022
You can sync any number of PDO supported databases

Features: Can backup any number of databases. No need to introduce column name only table name The Last id based data backup Support 12 different data

Tharusha Kavishan Udumulla 4 Aug 27, 2021
SleekwareDB is a NoSQL database storage service. A database storage service that can be used for various platforms and is easy to integrate.

SleekwareDB is a NoSQL database storage service. A database storage service that can be used for various platforms and is easy to integrate. NoSQL API

SleekwareDB 12 Dec 11, 2022
Pure PHP NoSQL database with no dependency. Flat file, JSON based document database.

Please give it a Star if you like the project ?? ❤️ SleekDB - A NoSQL Database made using PHP Full documentation: https://sleekdb.github.io/ SleekDB i

Kazi Mehedi Hasan 745 Jan 7, 2023
A complete, simple and powerful database framework written in PHP

BaseSQL BaseSQL is a complete database framework written in PHP. It was built to accelerate projects development by handle database connections and qu

Willian Pinheiro 2 Sep 21, 2021
The Enobrev\ORM library is a small framework of classes meant to be used for simply mapping a mysql database to PHP classes, and for creating simply SQL statements using those classes.

The Enobrev\ORM library is a small framework of classes meant to be used for simply mapping a mysql database to PHP classes, and for creating simply SQL statements using those classes.

Mark Armendariz 0 Jan 7, 2022
The lightweight PHP database framework to accelerate development

The lightweight PHP database framework to accelerate development Features Lightweight - Less than 100 KB, portable with only one file Easy - Extremely

Angel Lai 4.6k Dec 28, 2022
[READ ONLY] Subtree split of the Illuminate Database component (see laravel/framework)

Illuminate Database The Illuminate Database component is a full database toolkit for PHP, providing an expressive query builder, ActiveRecord style OR

The Laravel Components 2.5k Dec 27, 2022
Adjacency List’ed Closure Table database design pattern implementation for the Laravel framework.

ClosureTable This is a database manipulation package for the Laravel 5.4+ framework. You may want to use it when you need to store and operate hierarc

Yan Ivanov 441 Dec 11, 2022
Phpstan-dba - database handling related class reflection extension for PHPStan & framework-specific rules

database handling class reflection extension for PHPStan This extension provides following features: PDO->query knows the array shape of the returned

Markus Staab 175 Dec 29, 2022
The fastest pure PHP database framework with a powerful static code generator, supports horizontal scale up, designed for PHP7

Maghead 4.0.x IS CURRENTLY UNDER HEAVY DEVELOPMENT, API IS NOT STABLE Maghead is an open-source Object-Relational Mapping (ORM) designed for PHP7. Mag

Maghead 477 Dec 24, 2022
A package for using Google Datastore as a database driver

Laravel Eloquent for Google Datastore A package for using Google Datastore as a database driver. By using this package, you can use query builder and

A1 Comms Ltd 3 Apr 26, 2022
PHP Object Model Manager for Postgresql

POMM: The PHP Object Model Manager for Postgresql Note This is the 1,x version of Pomm. This package is not maintained anymore, the stable Pomm 2.0 is

Grégoire HUBERT 161 Oct 17, 2022
Satis composer repository manager with a Web UI

Satisfy Satis Composer repository manager with a simple web UI. Introduction Satisfy provides: a Web UI: A CRUD to manage your satis configuration fil

Ludovic Fleury 470 Dec 28, 2022