Chapter 5. Backup Sources

You can configure multiple backups in one configuration file. Each backup is represented by a <backup> Tag. To configure the data that is stored use the <source> Tag.

Table 5.1. Supported types of backup sources:

TypeDescription
arangodumpBackup ArangoDB with the arangodump command line tool.
elasticdumpBackup Elasticsearch with the elasticdump command line tool.
influxdumpBackup Influxdb with the influxd command line tool.
ldapdumpBackup LDAP data with the ldapdump command line tool.
mongodumpBackup MongoDB with the mongodump command line tool.
mysqldumpBackup MySQL with the mysqldump command line tool.
pgdumpBackup PostgreSQL with the pg_dump command line tool.
redisBackup redis with the redis-cli command line tool.
rsyncCollect files via the rsync command line tool.
tarBackup a directory with the tar command line tool.
xtrabackupBackup MySQL with the Percona xtrabackup command line tool.


ArangoDB

Backup a ArangoDB database with arangodump.

Table 5.2. arangodump-Options

NameValueRequiredDefaultDescription
endpointstringnotcp://localhost:8529URI to your ArangoDB endpoint.
usernamestringnonullUsername for the ArangoDB authentication.
passwordstringnonullPassword for the ArangoDB authentication.
disableAuthenticationbooleannofalseDisable the ArangoDB authentication.
databasestringno_systemDatabase to backup.
dumpDatabooleannotrueDump database data.
includeSystemCollectionsbooleannofalseDump system collections as well.
collectionsstringnoallList of collections to dump.
pathToArangoDumpstringno Custom arangodump executable location.


Example 5.1: arangodump XML example

<!-- source arangodump -->
<source type="arangodump">
  <option name="database" value="myDatabase" />
  <option name="dumpData" value="true" />
  <option name="collections" value="myCollection1,myCollection2" />
</source>


Example 5.2: arangodump JSON example

{
  "type": "arangodump",
  "options": {
    "database": "myDatabase",
    "dumpData": "true",
    "collections": "myCollection1,myCollection2"
  }
}


Elastic

Backup a Elastic index with elasticdump.

Table 5.3. arangodump-Options

NameValueRequiredDefaultDescription
hoststringnolocalhost:9200URI to your Elastic host.
userstringnonullUsername for the Elastic authentication.
passwordstringnonullPassword for the Elastic authentication.
indexstringnoallIndex name to backup.
typestringdatatrueElastic type to dump.
pathToElasticDumpstringno Custom elasticdump executable location.


Example 5.3: elasticdump XML example

<!-- source elasticdump -->
<source type="elasticdump">
  <option name="index" value="myIndex" />
</source>


Example 5.4: elasticdump JSON example

{
  "type": "elasticdump",
  "options": {
    "index": "myIndex"
  }
}


InfluxDB - influxdump

Backup an InfluxDB database with influxdump.

Table 5.4. influxdump-Options

NameValueRequiredDefaultDescription
hoststringnolocalhost:8088Hostname and port of your InfluxDB-Server.
databasestringnoallName of database you want to backup, all by default.
pathToInfluxdumpstringno Custom influxdump executable location.


Example 5.5: influxdump XML example

<!-- source influxdump -->
<source type="influxdump">
  <option name="host" value="localhost:8088"/>
  <option name="database" value="myDatabase"/>
</source>


Example 5.6: influxdump JSON example

{
  "type": "influxdump",
  "options": {
    "host": "localhost:8088",
    "database": "myDatabase"
  }
}


LDAP - ldapdump

Backup you LDAP data with ldapdump.

Table 5.5. ldapdump-Options

NameValueRequiredDefaultDescription
hoststringnolocalhostHostname of you LDAP server.
portintnoallPort to connect to your LDAP server.
searchBasestringno LDAP search base.
filterstringno LDAP search filter.
attrsstringno LDAP search attributes.
pathToLdapdumpstringno Custom path to ldapdump binary.


Example 5.7: influxdump XML example

<!-- source ldapdump -->
<source type="ldapdump">
  <option name="host" value="localhost"/>
  <option name="searchBase" value="ou=Users,dc=fr"/>
</source>


Example 5.8: influxdump JSON example

{
  "type": "ldapdump",
  "options": {
    "host": "localhost",
    "searchBase": "ou=Users,dc=fr"
  }
}


MongoDB

Backup a MongoDB database with mongodump.

Table 5.6. mongodump-Options

NameValueRequiredDefaultDescription
hoststringnolocalhostHostname of your MongoDB-Server.
userstringnoOS-UserUsername for the MongoDB authentication.
passwordstringnonullPassword for the MongoDB authentication.
authenticationDatabasestringnonullMongoDB database that holds the user credentials.
databasesstringnoallList of databases you want to backup, all by default.
excludeCollectionsstringnonullList of collections you don't want to backup.
excludeCollectionsWithPrefixstringnonullList of collection prefixes to exclude matching collections from backup.
pathToMongodumpstringno Custom mongodump executable location.


Example 5.9: mongodump XML example

<!-- source mongodump -->
<source type="mongodump">
  <option name="databases" value="myDatabase"/>
  <option name="user" value="user.name"/>
  <option name="password" value="topsecret"/>
  <option name="excludeCollections" value="collectionFoo,collectionBar"/>
</source>


Example 5.10: mongodump JSON example

{
  "type": "mongodump",
  "options": {
    "databases": "myDatabase",
    "user": "user.name",
    "password": "topsecret",
    "excludeCollections": "collectionFoo,collectionBar"
  }
}


MySQL - mysqldump

Backup a MySQL database with mysqldump.

Table 5.7. mysqldump-Options

NameValueRequiredDefaultDescription
hoststringnolocalhostHostname of your MySQL-Server.
portintegernonullPort of your MySQL-Server.
userstringnoOS-UserUsername for the MySQL authentication.
passwordstringnonullPassword for the MySQL authentication.
databasesstringnoallList of databases you want to backup, all by default.
ignoreTablesstringnonullList of tables you don't want to backup.
filePerTabletrue | falsenofalseCreate directory with separate files for each table.
structureOnlystringnonullList of tables where only the table structure will be stored. Can not be used with filePerTable
hexBlobtrue | falsenofalseUse the --hex-blob option to dump blob fields in hex.
lockTablestrue | falsenonullUse the --lock-tables option to lock tables during the dump.
singleTransactiontrue | falsenonullUse the --single-transaction option to add BEGIN SQL statement before dumping data from server.
sslCastringno Path to your ssl-ca file.
skipExtendedInserttrue | falsenofalseDo not use multiple-row INSERT syntax.
skipTriggerstrue | falsenofalseDo not execute triggers during backup.
pathToMysqldumpstringno Custom mysqldump executable location.


Example 5.11: mysqldump XML example

<!-- source mysqldump -->
<source type="mysqldump">
  <option name="databases" value="myDatabase"/>
  <option name="user" value="user.name"/>
  <option name="password" value="topsecret"/>
  <option name="ignoreTable" value="tableFoo,tableBar"/>
  <option name="structureOnly" value="logTable1,logTable2"/>
</source>


Example 5.12: mysqldump JSON example

{
  "type": "mysqldump",
  "options": {
    "databases": "myDatabase",
    "user": "user.name",
    "password": "topsecret",
    "ignoreTable": "tableFoo,tableBar",
    "structureOnly": "logTable1,logTable2"
  }
}


MySQL - xtrabackup

Backup a MySQL database with Percona xtrabackup.

Table 5.8. xtrabackup-options

NameValueRequiredDefaultDescription
dataDirstringno MySQL data directory.
hoststringnolocalhostHost to connect to.
userstringnoOS-UserUser to connect with.
passwordstringnofalsePassword to authenticate the user.
databasesstringno-List of databases to backup, all by default.
includestringno-Pattern to include databases and tables to the backup e.g. ^mydatabase[.]mytable.
pathToXtraBackupstringno Custom xtrabackup executable location.


Example 5.13: xtrabackup XML example

<!-- source xtrabackup -->
<source type="xtrabackup">
  <option name="databases" value="myDB1,myDB2" />
</source>


Example 5.14: xtrabackup JSON example

{
  "type": "xtrabackup",
  "options": {
    "databases": "myDB1,myDB2"
  }
}


pgdump

Backup PostgreSQL databases using the pg_dump command line tool.

Table 5.9. pgdump-Options

NameValueRequiredDefaultDescription
hoststringno-Host to connect to.
portintegerno-Port to use to connect to the PostgreSQL server.
userstringno-User to use to connect.
passwordstringno-Password to use to authenticate.
databasestringyes-Database to backup.
schemaOnlyboolnofalseDump only schema information.
dataOnlystringnofalseDump no schema information.
schemasstringno-List of schemas to dump, separated by comma.
excludeSchemasstringno-List of schemas to exclude, separated by comma.
tablesstringno-List of tables to backup, separated by comma.
excludeTablesstringno-List of tables to exclude, separated by comma.
excludeTableDatastringno-List of tables where data is not dumped, separated by comma.
noPermissionsboolnofalseDon't dump any permission schemas.
noOwnerboolnofalseDon't dump any owner changing statements.
formatstringnoplainDump format, plain, custom, directory.
encodingstringno-Set the dump encoding.
pathToPgdumpstringno Custom pgdump executable location.


Example 5.15: pgdump XML example

<!-- source pgdump -->
<source type="pgdump">
  <option name="database" value="myDstabase"/>
  <option name="user" value="myName"/>
  <option name="password" value="topSecret"/>
</source>


Example 5.16: pgdump JSON example

{
  "type": "pgdump",
  "options": {
    "database": "myDatabase",
    "user": "myName",
    "password": "topSecret",
  }
}


redis

Backup Redis data structure store using redis-cli.

Table 5.10. redis-Options

NameValueRequiredDefaultDescription
pathToRedisDatastringyes-Path to the Redis data .rdb file.
portintegerno6379Port to use to connect to the redis server.
passwordstringno-Password to use to authenticate.
pathToRedisClistringno Custom redis-cli executable location.


Example 5.17: redis XML example

<!-- source redis -->
<source type="redis">
  <option name="pathToRedisData" value="/var/lib/redis/6379/dump.rdb"/>
</source>


Example 5.18: redis JSON example

{
  "type": "redis",
  "options": {
    "pathToRedisData": "/var/lib/redis/6379/dump.rdb"
  }
}


rsync

Backup files via the rsync command line tool.

Table 5.11. rsync-Options

NameValueRequiredDefaultDescription
pathstringyes-Path to file/directory to sync.
hoststringno-Host to connecto to.
userstringno-User to use to authenticate.
deletestringnofalseRemove deleted files locally as well.
isDirSyncstringnofalseKeep the directory instead of archiving it at every PHPBU execution.
pathToRsyncstringno Custom rsync executable location.


Example 5.19: rsync XML example

<!-- source rsync -->
<source type="rsync">
  <option name="path" value="/tmp/foo"/>
</source>


Example 5.20: rsync JSON example

{
  "type": "rsync",
  "options": {
    "path": "/tmp/foo"
  }
}


Directories

Backup directories using tar.

Table 5.12. tar-Options

NameValueRequiredDefaultDescription
pathstringyes-Path to the source directory.
excludestringno-Comma separated list of paths to exclude.
ignoreFailedReadbooleannofalseIgnore changing source directory.
incrementalFilestringno-Incremental cache file.
forceLevelZeroOnstringno-Force a level zero backup at specific times.
compressProgramstringno-Set custom compression program f.e. lbzip2.
removeSourceDirbooleannofalseRemove the directory after compression.
throttlestringno-Throttle IO throughput via 'pv' (Linux/Unix only).
pathToTarstringno Custom tar executable location.


Example 5.21: tar XML example

<!-- source tar -->
<source type="tar">
  <option name="path" value="htdocs/uploads"/>
</source>


Example 5.22: tar JSON example

{
  "type": "tar",
  "options": {
    "path": "htdocs/uploads"
  }
}


Incremental backups

Doing incremental backups with tar is also supported. To activate incremental backups you have to specify a cache file where tar can store state information. Tar will then only do incremental backups unless told otherwise. You can force full backups (level zero backups) by removing the cache file manually or by using the forceLevelZeroOn option. In the following example incremental backups are activated by storing the backup state in a metadata.snar file and phpbu will force a level zero backup every Sunday and Wednesday. The backups on Monday, Tuesday, Thursday, Friday and Saturday will only contain the changes to the day before. To for example restore a Saturday backup you will need the backups from Wednesday, Thursday, Friday and Saturday.

Please configure your cleanup strategies accordingly to not use any data.

Example 5.23: tar XML example

<!-- source tar -->
<source type="tar">
  <option name="path" value="htdocs/uploads"/>
  <option name="incrementalFile" value="path/to/metadata.snar" />
  <option name="forceLevelZeroOn" value="%D@Sun|Wed" />
</source>


forceLevelZeroOn

date mask @ value [|value]

%D @ Sun|Web - Level zero backups on Sunday, and Wednesday

%H @ 3|15 - Level zero backups at 3am, and 15pm

Exclude files or directories

If you want to exclude some files or directories from the created tar file.

Example 5.24: tar XML example

<!-- source tar -->
<source type="tar">
  <option name="path" value="htdocs/uploads"/>
  <option name="exclude" value="folderA,fileA.txt,folderB"/>
</source>


Example 5.25: tar JSON example

{
  "type": "tar",
  "options": {
    "path": "htdocs/uploads",
    "exclude": "folderA,fileA.txt,folderB"
  }
}


IO Throttling

If you are experiencing high CPU load during your backups with tar you can throttle the IO to reduce CPU load.

Example 5.26: Throttling XML example

<!-- source tar -->
<source type="tar">
  <option name="path" value="htdocs/uploads"/>
  <option name="throttle" value="5m"/>
</source>


With a configuration like in the example above you make sure that you only write 5 Megabytes each second. This way your backup may take longer, but your CPU is able to handle other stuff as well.

This is done via the CLI tool pv. To use this feature you must have pv installed on your server. If you are using PHPBU on Windows, this feature is not available.

For more information on pv have a look here

Please open a ticket on GitHub to suggest improvements to this page. Thanks!