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 f.e. 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 f.e.
password in case you have to use different credentials to
backup your database.
You can use every option the mysqldump source supports f.e. 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 to 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