Chapter 8. Sync Backups

It's a best practice to NOT store your backups locally, or at least not only storing them locally. With PHPBU Sync adapters you can copy your backups to different locations.

Caution

If you are syncing your backup to a cloud service it's advised to encrypt your backup beforehand. Especially if your backup contains personal identifiable information.

PHPBU supports cleaning up you locally stored backups by configuring a Cleanup. Note that Cleanup configurations do not affect remote files synced with Sync configurations.

But some Sync adapters support cleaning up remote files as well. This is done by using cleanup.* options in your Sync configuration. In order to better understand how remote cleanups work and how they are configured have a look at the Cleanups section.

Table 8.1. Supported types of syncs:

TypeDescriptionRemote Cleanup
amazonSync your backup to your Amazon S3 account.yes
DropboxSync your backup to a Dropbox account.yes
Google DriveSync your backup to a Google Drive account.yes
OpenStackSync your backups to an OpenStack storage.yes
rsyncSync your backups with rsync.no
sftpSync your backup to a server via SFTP.yes
SoftLayer Object StorageSync your backup to a Softlayer Object Storage account.no


Amazon S3

Sync your backup to an amazon S3 account.

If you are not using the PHAR Version you have to require "aws/aws-sdk-php": "^3.10" in your composer file.

Table 8.2. amazons3-Options

NameValueRequiredDefaultDescription
keystringyes-The amazon s3 key.
secretstringyes-The amazon S3 secret.
bucketstringyes-A bucket where to store the backup.
regionstringyes-The region where the bucket is located e.g. 'eu-central-1'.
pathstringno/Path where to store the backup in your bucket.
useMultiPartUploadbooleannofalseUse Amazon S3 MultiPartUpload functionality.
cleanup.typestringno-The remote cleanup strategy (capacity|oudated|quantity|stepwise).
cleanup.*stringno- The remote cleanup strategy settings. For example "cleanup.size" if you use "cleanup.type" = "capacity". For details have a look at the corresponding Cleanup configurations.


Example 8.1: amazons3 XML example

<!-- sync amazon s3 -->
<sync type="amazons3">
  <option name="key" value="myAwsKey"/>
  <option name="secret" value="myAwsSecret"/>
  <option name="bucket" value="backup"/>
  <option name="region" value="eu-central-1"/>
  <option name="path" value="/some/dir"/>
</sync>


Example 8.2: amazons3 JSON example

{
  "type": "amazons3",
  "options": {
    "key": "myAwsKey",
    "secret": "myAwsSecret",
    "bucket": "backup",
    "region": "eu-central-1",
    "path": "/some/dir",
    "useMultiPartUpload": "true"
  }
}


Dropbox

Sync your backup to a Dropbox account.

If you are not using the PHAR Version you have to require "dropbox/dropbox-sdk": "1.1.*" in your composer file.

Table 8.3. Dropbox-Options

NameValueRequiredDefaultDescription
tokenstringyes- The dropbox authentication token. Go to www.dropbox.com/developers/apps Create your app Choose: dropbox api app files and datastore yes provide some app name "my-dropbox-app" generate access token to authenticate connection to your dropbox
pathstringyes-Directory where to store the backup in your dropbox account.


Example 8.3: Dropbox XML example

<!-- sync dropbox -->
<sync type="dropbox">
  <option name="token" value="myCrazyLongApiTokenThatIGotFromDropbox"/>
  <option name="path" value="/some/dir"/>
</sync>
</section>


Example 8.4: Dropbox JSON example

{
  "type": "dropbox",
  "options": {
    "token": "myCrazyLongApiTokenThatIGotFromDropbox",
    "path": "/some/dir"
  }
}


Google Drive

Sync your backup to a Google Drive account.

If you are not using the PHAR Version you have to require "google/apiclient":"^2.0" in your composer file.

Table 8.4. Google Drive-Options

NameValueRequiredDefaultDescription
secretstringyes-Google Drive authentication json file.
accessstringyes-Json file containing your access token.
parentIdstringyes-The Google Drive element id where your backups should be stored.


If you are unsure on how to obtain the secret and access files or the directory ID have a look at sebastianfeldmann/phpbu-google-drive a utility to generate your access token and to list the files and their IDs from your Google Drive account.

Example 8.5: Google Drive XML example

<!-- sync dropbox -->
<sync type="googledrive">
  <option name="secret" value="config/google/secret.json"/>
  <option name="access" value="config/google/access.json"/>
  <option name="parentId" value="bkjnwqr8123njndcqw12r"/>
</sync>
</section>


Example 8.6: Google Drive JSON example

{
  "type": "googledrive",
  "options": {
    "secret": "config/google/secret.json",
    "access": "config/google/access.json",
    "parentId": "bkjnwqr8123njndcqw12r"
  }
}


OpenStack

Sync your backup to a provider supporting the OpenStack API.

Table 8.5. OpenStack-Options

NameValueRequiredDefaultDescription
auth_urlstringyes-The remote authentication url.
regionstringyes-The OpenStack region.
userstringyes-The user name for authentication.
passwordstringyes-The user password.
container_namestringyes-The name of the container to store the backup.
service_namestringnoswiftThe service to use for the upload.
pathstringno-Remote path to store the backup.


Example 8.7: OpenStack XML example

<!-- sync openstack -->
<sync type="openstack">
  <option name="auth_url" value="www.example.com"/>
  <option name="region" value="my-region"/>
  <option name="user" value="username"/>
  <option name="password" value="top-secret"/>
  <option name="path" value="/some/path"/>
</sync>


Example 8.8: OpenStack JSON example

{
  "type": "openstack",
  "options": {
    "auth_url": "www.example.com",
    "region": "my-region",
    "user": "username"
    "password": "my-secret"
    "path": "/some/path",
  }
}


Rsync

Sync your backup via the rsync command.

Table 8.6. rsync-Options

NameValueRequiredDefaultDescription
pathstringyes-The remote path where your backups should be synced to.
hoststringyes-The remote host where your backups should be synced to.
userstringnoOS-User The user to connect to the remote host. Make sure the user is able to connect without entering a password otherwise you get prompted for a password while executing phpbu.
dirsyncbooleannofalseSync the target directory instead of syncing only the target file.
deletebooleannofalseAdd the --delete option to the rsync call, so locally deleted files will be deleted remotely as well.
excludestringno-List of files to exclude from the sync separated by ":" e.g. "*.suffix:foo.bar".
argsstringno- Advanced mode to use completely custom options. "rsync {args}". WARNING: phpbu is not escaping this in any way so use with caution! Use %TARGET_FILE% and %TARGET_DIR% as reference to your created backup.


Example 8.9: rsync XML example

<!-- sync rsync -->
<sync type="rsync">
  <option name="path" value="/backup/some/path"/>
  <option name="dirsync" value="true"/>
  <option name="host" value="backup.example.com"/>
  <option name="user" value="backup"/>
</sync>


Example 8.10: rsync JSON example

{
  "type": "rsync",
  "options": {
    "path": "/backup/some/path",
    "dirsync": "true",
    "host": "backup.example.com",
    "user": "backup"
  }
}


SFTP / FTP

Copy your backup to another server via SFTP or FTP.

If you want to use SFTP and you are not using the PHAR version you have to require "phpseclib/phpseclib": "2.0.*@dev" in your composer file. For this to work you have to set the minimum-stability to dev.

If you want to use the FTP-Sync your PHP has to be compiled with --enable-ftp.

Table 8.7. (s)ftp-Options

NameValueRequiredDefaultDescription
hoststringyes-The host you want do copy your backups to.
userstringyes-The user you want to connect with.
passwordstringno-The password to authenticate the user. If 'key' is provided this will be used as private key password.
keystringno-Path to private key file to authenticate the user.
pathstringyes-The remote path where to copy the backup.
passivebooleannofalseUse passive ftp mode.


Example 8.11: sftp XML example

<!-- sync sftp -->
<sync type="sftp">
  <option name="host" value="backup.example.com"/>
  <option name="user" value="user.name"/>
  <option name="password" value="topsecret"/>
  <option name="path" value="backup/someName"/>
  <option name="passive" value="true"/>
</sync>


Example 8.12: sftp JSON example

{
  "type": "sftp",
  "options": {
    "host": "backup.example.com",
    "user": "user.name",
    "password": "topsecret",
    "path": "backup/someName",
    "passive": "false"
  }
}


If you want to use plain FTP just use ftp as type, options stay the same.

Softlayer Object Storage

Sync your backup to a Softlayer account.

If you are not using the PHAR Version you have to require "softlayer/objectstorage": "dev-master" in your composer file. For this to work you have to set the minimum-stability to dev.

Table 8.8. softlayer-Options

NameValueRequiredDefaultDescription
userstringyes-The user you want to connect with.
secretstringno-The api key to authenticate the user.
hoststringyes-The host you want do copy your backups to.
containerstringyes-The Object Storage Container where to put the backup.
pathstringyes-The remote path where to copy the backup.


Example 8.13: softlayer XML example

<!-- sync softlayer object storage -->
<sync type="softlayer">
  <option name="user" value="user.name"/>
  <option name="secret" value="topsecret"/>
  <option name="host" value="some.softlayer.domain.com"/>
  <option name="container" value="backup"/>
  <option name="path" value="/backup/someName"/>
</sync>


Example 8.14: softlayer JSON example

{
  "type": "softlayer",
  "options": {
    "user": "user.name",
    "secret": "topsecret",
    "host": "some.softlayer.domain.com",
    "container": "backup",
    "path": "/backup/someName"
  }
}


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