laravel-phpbu package integrates
phpbu into the Laravel
framework so you can use the
artisan command to execute your backups
and a Laravel style PHP configuration to set them up.
Use Composer to install the package.
composer require "phpbu/phpbu-laravel"
Add the package ServiceProvider to your
config/app.php configuration file.
'providers' => [ /* * phpbu Backup Service Providers... */ phpbu\Laravel\ServiceProvider::class, ];
Finally use the Laravel
to create a configuration skeleton by publishing the package.
php artisan vendor:publish --provider="phpbu\Laravel\ServiceProvider"
After publishing the ServiceProvider a
configuration file is created in your config directory.
There are two ways of configuring your backup.
Use the created
phpbu.php configuration file
Use a standard
phpbu.json configuration file
The main difference between those two options is the implemented feature set.
While the PHPBU configuration files give you full access to all features of PHPBU the Laravel configuration file currently does not support all features of PHPBU, for example: encryption.
The main concept of configuring backups stays the same. A backup consists of a source and a target. The source represents the data you want to backup. The target represents the location where you want to store your backup. You can add checks, cleanups and syncs to a backup to validate, cleanup or sync your backup to another location.
In the Laravel configuration file you can specify two types of backups,
databases (MySQL, PostgreSQL).
Define the directory you want to backup and the target location where to store your backup.
'directories' => [ [ 'source' => [ 'path' => storage_path('app'), 'options' => , ], 'target' => [ 'dirname' => storage_path('/backup/app'), 'filename' => 'app-%Y%m%d-%H%i.tar', 'compression' => 'bzip2', ] ] ],
Just define the Laravel database connection configured in your
you want to backup and you are done. You can overwrite every setting defined with the specific option, for example
password in case you have to use different credentials to
backup your database.
You can use every option the mysqldump source supports for example to exclude some tables. Just use the option-name as index and the option-value as value.
'databases' => [<emphasise> [ 'source' => [ 'connection' => 'mysql', 'options' =>  ], 'target' => [ 'dirname' => storage_path('backup/db'), 'filename' => 'dump-%Y%m%d-%H%i.sql', 'compression' => 'bzip2', ] ], ],
Add check, sync and cleanup definitions to your backup configuration.
'check' => [ 'type' => 'SizeMin', 'value' => '10B', ], 'sync' => [ 'filesystem' => 's3', 'path' => '/backups/db' ], 'cleanup' => [ 'type' => 'quantity', 'options' => [ 'amount' => '20' ] ]
To sync your backups you can use every filesystem defined in your Laravel
If you want to use a PHPBU configuration file your Laravel phpbu.php configuration should look something like this.
<?php return [ /* |-------------------------------------------------- | phpbu configuration |-------------------------------------------------- | | Path to a phpbu configuration xml or json file. */ 'phpbu' => base_path('phpbu.xml'), ];
For this to work you have to setup a valid phpbu.xml configuration file in your project root.
Remember that all paths in a PHPBU configuration have to be absolute or relative to the specified PHPBU configuration file.
To execute the backup use the
artisan command line tool.
php artisan phpbu:backup
To execute a dry-run without making any changes.
php artisan phpbu:backup --phpbu-simulate