Backup/Restore Storage Plugin API (Beta)

This topic describes how to develop a custom storage plugin with the Greenplum Database Backup/Restore Storage Plugin API.

Note: Only the Backup/Restore Storage Plugin API is a Beta feature. The storage plugins are supported features.

The Backup/Restore Storage Plugin API provides a framework that you can use to develop and integrate a custom backup storage system with the Greenplum Database gpbackup and gprestore utilities.

The Backup/Restore Storage Plugin API defines a set of interfaces that a plugin must support. The API also specifies the format and content of a configuration file for a plugin.

When you use the Backup/Restore Storage Plugin API, you create a plugin that the Greenplum Database administrator deploys to the Greenplum Database cluster. Once deployed, the plugin is available for use in certain backup and restore operations.

This topic includes the following subtopics:

Parent topic: Parallel Backup with gpbackup and gprestore

Plugin Configuration File

Specifying the --plugin-config option to the gpbackup and gprestore commands instructs the utilities to use the plugin specified in the configuration file for the operation.

The plugin configuration file provides information for both Greenplum Database and the plugin. The Backup/Restore Storage Plugin API defines the format of, and certain keywords used in, the plugin configuration file.

A plugin configuration file is a YAML file in the following format:

  1. executablepath: <path_to_plugin_executable>
  2. options:
  3. <keyword1>: <value1>
  4. <keyword2>: <value2>
  5. ...
  6. <keywordN>: <valueN>

gpbackup and gprestore use the **executablepath** value to determine the file system location of the plugin executable program.

The plugin configuration file may also include keywords and values specific to a plugin instance. A backup/restore storage plugin can use the **options** block specified in the file to obtain information from the user that may be required to perform its tasks. This information may include location, connection, or authentication information, for example. The plugin should both specify and consume the content of this information in keyword:value syntax.

A sample plugin configuration file for the Greenplum Database S3 backup/restore storage plugin follows:

  1. executablepath: $GPHOME/bin/gpbackup_s3_plugin
  2. options:
  3. region: us-west-2
  4. aws_access_key_id: notarealID
  5. aws_secret_access_key: notarealkey
  6. bucket: gp_backup_bucket
  7. folder: greenplum_backups

Plugin API

The plugin that you implement when you use the Backup/Restore Storage Plugin API is an executable program that supports specific commands invoked by gpbackup and gprestore at defined points in their respective life cycle operations:

  • The Greenplum Database Backup/Restore Storage Plugin API provides hooks into the gpbackup lifecycle at initialization, during backup, and at cleanup/exit time.

  • The API provides hooks into the gprestore lifecycle at initialization, during restore, and at cleanup/exit time.

  • The API provides arguments that specify the execution scope (master host, segment host, or segment instance) for a plugin setup or cleanup command. The scope can be one of these values.

    • master - Execute the plugin once on the master host.
    • segment_host - Execute the plugin once on each of the segment hosts.
    • segment - Execute the plugin once for each active segment instance on the host running the segment instance. The Greenplum Database hosts and segment instances are based on the Greenplum Database configuration when the back up started. The values segment_host and segment are provided as a segment host can host multiple segment instances. There might be some setup or cleanup required at the segment host level as compared to each segment instance.

The Backup/Restore Storage Plugin API defines the following call syntax for a backup/restore storage plugin executable program:

  1. <plugin_executable> <command> <config_file> <args>

where:

  • plugin\_executable - The absolute path of the backup/restore storage plugin executable program. This path is determined by the executablepath property value configured in the plugin’s configuration YAML file.
  • command - The name of a Backup/Restore Storage Plugin API command that identifies a specific entry point to a gpbackup or gprestore lifecycle operation.
  • config\_file - The absolute path of the plugin’s configuration YAML file.
  • args - The command arguments; the actual arguments differ depending upon the command specified.

Plugin Commands

The Greenplum Database Backup/Restore Storage Plugin API defines the following commands:

Command NameDescription
plugin_api_versionReturn the version of the Backup/Restore Storage Plugin API supported by the plugin. The only supported version is 0.3.0.
setup_plugin_for_backupInitialize the plugin for a backup operation.
backup_fileMove a backup file to the remote storage system.
backup_dataMove streaming data from stdin to a file on the remote storage system.
cleanup_plugin_for_backupClean up after a backup operation.
setup_plugin_for_restoreInitialize the plugin for a restore operation.
restore_fileMove a backup file from the remote storage system to a designated location on the local host.
restore_dataMove a backup file from the remote storage system, streaming the data to stdout.
cleanup_plugin_for_restoreClean up after a restore operation.

A backup/restore storage plugin must support every command identified above, even if it is a no-op.

Implementing a Backup/Restore Storage Plugin

You can implement a backup/restore storage plugin executable in any programming or scripting language.

The tasks performed by a backup/restore storage plugin will be very specific to the remote storage system. As you design the plugin implementation, you will want to:

  • Examine the connection and data transfer interface to the remote storage system.
  • Identify the storage path specifics of the remote system.
  • Identify configuration information required from the user.
  • Define the keywords and value syntax for information required in the plugin configuration file.
  • Determine if, and how, the plugin will modify (compress, etc.) the data en route to/from the remote storage system.
  • Define a mapping between a gpbackup file path and the remote storage system.
  • Identify how gpbackup options affect the plugin, as well as which are required and/or not applicable. For example, if the plugin performs its own compression, gpbackup must be invoked with the --no-compression option to prevent the utility from compressing the data.

A backup/restore storage plugin that you implement must:

  • Support all plugin commands identified in Plugin Commands. Each command must exit with the values identified on the command reference page.

Refer to the gpbackup-s3-plugin github repository for an example plugin implementation.

Verifying a Backup/Restore Storage Plugin

The Backup/Restore Storage Plugin API includes a test bench that you can run to ensure that a plugin is well integrated with gpbackup and gprestore.

The test bench is a bash script that you run in a Greenplum Database installation. The script generates a small (<1MB) data set in a Greenplum Database table, explicitly tests each command, and runs a backup and restore of the data (file and streaming). The test bench invokes gpbackup and gprestore, which in turn individually call/test each Backup/Restore Storage Plugin API command implemented in the plugin.

The test bench program calling syntax is:

  1. plugin_test_bench.sh <plugin_executable plugin_config>

Procedure

To run the Backup/Restore Storage Plugin API test bench against a plugin:

  1. Log in to the Greenplum Database master host and set up your environment. For example:

    1. $ ssh gpadmin@<gpmaster>
    2. gpadmin@gpmaster$ . /usr/local/greenplum-db/greenplum_path.sh
  2. Obtain a copy of the test bench from the gpbackup github repository. For example:

    1. $ git clone git@github.com:greenplum-db/gpbackup.git

    The clone operation creates a directory named gpbackup/ in the current working directory.

  3. Locate the test bench program in the gpbackup/master/plugins directory. For example:

    1. $ ls gpbackup/master/plugins/plugin_test_bench.sh
  4. Copy the plugin executable program and the plugin configuration YAML file from your development system to the Greenplum Database master host. Note the file system location to which you copied the files.

  5. Copy the plugin executable program from the Greenplum Database master host to the same file system location on each segment host.

  6. If required, edit the plugin configuration YAML file to specify the absolute path of the plugin executable program that you just copied to the Greenplum segments.

  7. Run the test bench program against the plugin. For example:

    1. $ gpbackup/master/plugins/plugin_test_bench.sh /path/to/pluginexec /path/to/plugincfg.yaml
  8. Examine the test bench output. Your plugin passed the test bench if all output messages specify RUNNING and PASSED. For example:

    1. # ----------------------------------------------
    2. # Starting gpbackup plugin tests
    3. # ----------------------------------------------
    4. [RUNNING] plugin_api_version
    5. [PASSED] plugin_api_version
    6. [RUNNING] setup_plugin_for_backup
    7. [RUNNING] backup_file
    8. [RUNNING] setup_plugin_for_restore
    9. [RUNNING] restore_file
    10. [PASSED] setup_plugin_for_backup
    11. [PASSED] backup_file
    12. [PASSED] setup_plugin_for_restore
    13. [PASSED] restore_file
    14. [RUNNING] backup_data
    15. [RUNNING] restore_data
    16. [PASSED] backup_data
    17. [PASSED] restore_data
    18. [RUNNING] cleanup_plugin_for_backup
    19. [PASSED] cleanup_plugin_for_backup
    20. [RUNNING] cleanup_plugin_for_restore
    21. [PASSED] cleanup_plugin_for_restore
    22. [RUNNING] gpbackup with test database
    23. [RUNNING] gprestore with test database
    24. [PASSED] gpbackup and gprestore
    25. # ----------------------------------------------
    26. # Finished gpbackup plugin tests
    27. # ----------------------------------------------

Packaging and Deploying a Backup/Restore Storage Plugin

Your backup/restore storage plugin is ready to be deployed to a Greenplum Database installation after the plugin passes your testing and the test bench verification. When you package the backup/restore storage plugin, consider the following:

  • The backup/restore storage plugin must be installed in the same file system location on every host in the Greenplum Database cluster. Provide installation instructions for the plugin indentifying the same.
  • The gpadmin user must have permission to traverse the file system path to the backup/restore plugin executable program.
  • Include a template configuration file with the plugin.
  • Document the valid plugin configuration keywords, making sure to include the syntax of expected values.
  • Document required gpbackup options and how they affect plugin processing.