Working with Custom Backup Storages

Plesk provides the option of choosing a remote storage to keep your backups, such as an FTP server. Using Plesk SDK, it is also possible to add more different custom backup storages, and enable Plesk to use them to keep the backups.

Class pm_Hook_Backup_Transport defines a set of methods, which describe the necessary functions of authentication and authorization, working with files, etc. With the help of this hook, Plesk Backup Manager knows about the new custom storage, and provides all the same operations and information that are available for the default backup storages.

To illustrate the subject, the following sample project is provided by Plesk: https://github.com/plesk/ext-cloud-backup-example.

Authorization

As the extension developer, you may choose to handle authorization, using either OAuth2 or login and password.

Login and Password

The login and password (or access key/secret key) used for authentication with the custom storage are specified on the custom storage settings sub-form, pm_Hook_Backup_Transport::getSettingsSubForm(), along with other settings. The entered login and password must be validated in the pm_Form_SubForm::isValid() method.

OAuth2

OAuth2 authorization must be implemented in the pm_Hook_Backup_Transport::authorize() method. This method is always called before displaying the custom storage settings sub-form, pm_Hook_Backup_Transport::getSettingsSubForm().

Verification

Method pm_Hook_Backup_Transport::check() should be used to make sure all the functions involved in backup and restore operations (e.g., CRUD) are available. This method is called before each backup operation.

Remarks
  1. Make sure to use the Plesk Key-Value Storage to encrypt and safely store passwords and access tokens.
  2. Create separate directories in the custom storage root directory for the different objects to keep their backup files from mixing.

Working with Files

Writing to Custom Storage

The methods responsible for writing the created backup to the custom storage are called in the following order:

  1. openFileWrite()
  2. [multiple calls] appendFile()
  3. closeFile()

Some storages may require the size of the file written to be known before starting the file upload. This information is not available during the Plesk backup creation. In this case, the backup should be split into a set of files of a known size. The files should be named in the following manner:

  1. backup.tar
  2. backup.tar1
  3. backup.tar2
  4. ...

This way, Plesk Backup Manager will be able to correctly display information and work with the backup.

Reading from Custom Storage

The methods responsible for reading the backup from the custom storage are called in the following order:

  1. openFileRead()
  2. [multiple calls] readFile()
  3. closeFile()

Testing Your Extension with Custom Storage

To make sure all the backup/restore-related extension functions work properly, run the following command:

/opt/psa/admin/bin/pmm-ras --check-repository --debug --verbose --dump-storage=ext://<ext name>/subscription/<id>/ --session-path=/var/log/plesk/PMM