Chapter 8. Sync Backups

It's considered 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 your 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
Azure BlobSync your backup to your Azure Blob storage.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
Yandex DiskSync your backup to a Yandex 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-The bucket name where the backup is stored.
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|outdated|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"
  }
}


Azure Blob

Sync your backup to an Azure Blob storage.

If you are not using the PHAR version you have to require "microsoft/azure-storage-blob": "~1.4" in your Composer file.

Table 8.3. azureblob-Options

NameValueRequiredDefaultDescription
connection_stringstringyes-The Azure Blob storage account connection string.
container_namestringyes-A container where to store the backup.
pathstringno/Path where to store the backup in your container.
cleanup.typestringno-The remote cleanup strategy (capacity|outdated|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.3: azureblob XML example

<!-- sync azure blob -->
<sync type="azureblob">
  <option name="connection_string" value="DefaultEndpointsProtocol=[http|https];AccountName=[yourAccount];AccountKey=[yourKey]"/>
  <option name="container_name" value="backup"/>
  <option name="path" value="/some/dir"/>
</sync>


Example 8.4: azureblob JSON example

{
  "type": "azureblob",
  "options": {
    "connection_string": "DefaultEndpointsProtocol=[http|https];AccountName=[yourAccount];AccountKey=[yourKey]",
    "container_name": "backup",
    "path": "/some/dir"
  }
}


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.4. 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.5: Dropbox XML example

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


Example 8.6: 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.5. 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.7: 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.8: 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.6. 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.9: 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.10: 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.7. 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.11: 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.12: 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.8. (s)ftp-Options

NameValueRequiredDefaultDescription
hoststringyes-The host you want to copy your backups to.
portintegerno22The port you want to connect 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.13: sftp XML example

<!-- sync sftp -->
<sync type="sftp">
  <option name="host" value="backup.example.com"/>
  <option name="port" value="22"/>
  <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.14: sftp JSON example

{
  "type": "sftp",
  "options": {
    "host": "backup.example.com",
    "port": 22,
    "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.9. softlayer-Options

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


Example 8.15: 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.16: softlayer JSON example

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


Yandex Disk

Sync your backup to Yandex account.

If you are not using the PHAR version you have to require "arhitector/yandex": "^2.0" in your Composer file.

This is what you have to do:

  1. Go to https://oauth.yandex.ru/client/new

  2. Create your app

  3. Check all disk permissions

  4. Generate access token

  5. Go to https://oauth.yandex.ru/authorize?response_type=token&client_id=APP_ID (replace APP_ID with ID given to you)

  6. Then you should get token parameter from query parameters of opened page

Table 8.10. softlayer-Options

NameValueRequiredDefaultDescription
userstringyes-The user you want to connect with.
tokenstringno-The API token to authenticate the user.
pathstringyes-The remote path where to put the backup.


Example 8.17: Yandex XML example

<!-- sync yandex disk -->
<sync type="yandex-disk">
  <option name="token" value="mnahg6-1knl2l2-b1vf4"/>
  <option name="path" value="/backup/someName"/>
</sync>


Example 8.18: Yandex JSON example

{
  "type": "yandex-disk",
  "options": {
    "user": "mnahg6-1knl2l2-b1vf4",
    "path": "/backup/someName"
  }
}


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