To use PHPBU and create your backups you first have to create a configuration file.
The configuration of PHPBU is done with a simple XML file. You can validate your config files with the respective PHPBU schema definition found at schema.phpbu.de.
You should name your configuration file phpbu.xml
or phpbu.xml.dist
so you don't have to specify the path with the --configuration
option.
The following skeleton is a good point to start and get into detail from here.
Example 2.1: XML-Configuration
<?xml version="1.0" encoding="UTF-8"?> <phpbu xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://schema.phpbu.de/3.1/phpbu.xsd"> <backups> <backup> <!-- backup source --> <source type="mysqldump"> <option name="databases" value="mydbname"/> <option name="user" value="user.name"/> <option name="password" value="topsecret"/> </source> <!-- where should the backup be stored --> <target dirname="backup/mysql" filename="mysqldump-%Y%m%d-%H%i.sql" compress="bzip2"/> <!-- check the created backup --> <check type="SizeMin" value="10M"/> <!-- cleanup the backup location as soon as all created backups exceed 500MB remove oldest backups --> <cleanup type="Capacity"> <option name="size" value="500M"/> </cleanup> </backup> </backups> </phpbu>
The XML root element with at least xmlns:xsi and xsi:noNamespaceSchemaLocation.
Table 2.1. <phpbu> attributes
Name | Values | Required | Default | Description |
---|---|---|---|---|
bootstrap | filename | no | null | Include a php file to extend PHPBU |
verbose | true | false | no | false | Controls the output verbosity |
debug | true | false | no | false | Controls the debug output |
Configures a backup process. You can have as many of these as you need.
Table 2.2. <backup> attributes
Name | Values | Required | Default | Description |
---|---|---|---|---|
name | string | no | null | A custom name for your backup used in the PHPBU output. |
stopOnError | true | false | no | false | Tells if the execution of phpbu will be stopped if this backup fails. |
Defines the data that is backed up.
Table 2.3. <source> attributes
Name | Values | Required | Default | Description |
---|---|---|---|---|
type | string | yes | - | Type of backup, Chapter 9 has a list of all supported source types. |
Defines where the backup is stored.
Table 2.4. <target> attributes
Name | Values | Required | Default | Description |
---|---|---|---|---|
dirname | string | yes | - | Path to the directory where the backup is stored, absolute or relative to the config file. |
filename | string | yes | - | Filename of the stored backup. |
compress | string | no | null | Type of compressor to use to compress the backup. |
Specifies what kind of tests should be performed to validate the backup.
Table 2.5. <check> attributes
Name | Values | Required | Default | Description |
---|---|---|---|---|
type | string | yes | - | Type of check, Chapter 5 has a list of all supported check types. |
value | string | yes | - | Value the backup is getting checked against. |
Specifies what kind of encryption should be used to encrypt the backup.
Table 2.6. <crypt> attributes
Name | Values | Required | Default | Description |
---|---|---|---|---|
type | string | yes | - | Type of encryption, Chapter 6 has a list of all supported crypt types. |
skipOnFailure | true | false | no | false | You can still execute the encryption, even of some failure occurred. |
Copy the created backup to another location.
Table 2.7. <sync> attributes
Name | Values | Required | Default | Description |
---|---|---|---|---|
type | string | yes | - | Type of sync, Chapter 7 has a list of all supported sync types. |
skipOnFailure | true | false | no | false | You can still execute the sync, even of some failure occurred. |
Tells phpbu which files to delete after a successful backup.
Table 2.8. <cleanup> attributes
Name | Values | Required | Default | Description |
---|---|---|---|---|
type | string | yes | - | Type of cleanup, Chapter 8 has a list of all supported cleanup types. |
skipOnFailure | true | false | no | - | You can still execute the cleanup, even of some failure occurred. |
This is roughly the same skeleton as shown above at the XML-Section.
Example 2.2: JSON-Configuration
{ "verbose": true, "logging": [ { "type": "json", "target": "backup/json.log" } ], "backups": [ { "source": { "type": "mysqldump", "options": { "databases": "mydbname", "user": "user.name", "password": "topsecret" } }, "target": { "dirname": "backup", "filename": "mysql-%Y%m%d-%H%i.sql", "compress": "bzip2" }, "checks": [ { "type": "sizemin", "value": "10M" } ], "syncs": [ { "type": "sftp", "options": { "host": "backup.example.com", "user": "user.name", "password": "topsecret", "path": "backup/someName" } } ], "cleanup": { "type": "Capacity", "options": { "size": "200M" } } } ] }
Scheduling your backups is not part of phpbu. Nevertheless here is an example how to do it with Cron. Adding one of the following lines to your crontab will execute your backup every morning at 3:10 AM.
Example 2.3: Crontab example
# +------------------------- min (0 - 59) # | +-------------------- hour (0 - 23) # | | +--------------- day of month (1 - 31) # | | | +---------- month (1 - 12) # | | | | +----- day of week (0 - 7) (Sunday=0 or 7) # | | | | | # * * * * * # this requires phpbu to be in the cron users path 10 3 * * * phpbu --configuration=/var/www/my-backup/phpbu.xml # alternatively you can specify the full path #10 3 * * * /home/user/bin/phpbu.phar --configuration=/var/www/my-backup/phpbu.xml