Cloud Spanner V1 Client - Class DatabaseAdminClient (1.57.0)

Reference documentation and code samples for the Cloud Spanner V1 Client class DatabaseAdminClient.

Service Description: Cloud Spanner Database Admin API

The Cloud Spanner Database Admin API can be used to:

  • create, drop, and list databases
  • update the schema of pre-existing databases
  • create, delete and list backups for a database
  • restore a database from an existing backup

This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:

$databaseAdminClient = new DatabaseAdminClient();
try {
    $formattedParent = $databaseAdminClient->instanceName('[PROJECT]', '[INSTANCE]');
    $backupId = 'backup_id';
    $formattedSourceBackup = $databaseAdminClient->backupName('[PROJECT]', '[INSTANCE]', '[BACKUP]');
    $expireTime = new Timestamp();
    $operationResponse = $databaseAdminClient->copyBackup($formattedParent, $backupId, $formattedSourceBackup, $expireTime);
    $operationResponse->pollUntilComplete();
    if ($operationResponse->operationSucceeded()) {
        $result = $operationResponse->getResult();
    // doSomethingWith($result)
    } else {
        $error = $operationResponse->getError();
        // handleError($error)
    }
    // Alternatively:
    // start the operation, keep the operation name, and resume later
    $operationResponse = $databaseAdminClient->copyBackup($formattedParent, $backupId, $formattedSourceBackup, $expireTime);
    $operationName = $operationResponse->getName();
    // ... do other work
    $newOperationResponse = $databaseAdminClient->resumeOperation($operationName, 'copyBackup');
    while (!$newOperationResponse->isDone()) {
        // ... do other work
        $newOperationResponse->reload();
    }
    if ($newOperationResponse->operationSucceeded()) {
        $result = $newOperationResponse->getResult();
    // doSomethingWith($result)
    } else {
        $error = $newOperationResponse->getError();
        // handleError($error)
    }
} finally {
    $databaseAdminClient->close();
}

Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parseName method to extract the individual identifiers contained within formatted names that are returned by the API.

Methods

backupName

Formats a string containing the fully-qualified path to represent a backup resource.

Parameters
NameDescription
project string
instance string
backup string
Returns
TypeDescription
stringThe formatted backup resource.

cryptoKeyName

Formats a string containing the fully-qualified path to represent a crypto_key resource.

Parameters
NameDescription
project string
location string
keyRing string
cryptoKey string
Returns
TypeDescription
stringThe formatted crypto_key resource.

databaseName

Formats a string containing the fully-qualified path to represent a database resource.

Parameters
NameDescription
project string
instance string
database string
Returns
TypeDescription
stringThe formatted database resource.

instanceName

Formats a string containing the fully-qualified path to represent a instance resource.

Parameters
NameDescription
project string
instance string
Returns
TypeDescription
stringThe formatted instance resource.

parseName

Parses a formatted name string and returns an associative array of the components in the name.

The following name formats are supported: Template: Pattern

  • backup: projects/{project}/instances/{instance}/backups/{backup}
  • cryptoKey: projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{crypto_key}
  • database: projects/{project}/instances/{instance}/databases/{database}
  • instance: projects/{project}/instances/{instance}

The optional $template argument can be supplied to specify a particular pattern, and must match one of the templates listed above. If no $template argument is provided, or if the $template argument does not match one of the templates listed, then parseName will check each of the supported templates, and return the first match.

Parameters
NameDescription
formattedName string

The formatted name string

template string

Optional name of template to match

Returns
TypeDescription
arrayAn associative array from name component IDs to component values.

getOperationsClient

Return an OperationsClient object with the same endpoint as $this.

Returns
TypeDescription
Google\ApiCore\LongRunning\OperationsClient

resumeOperation

Resume an existing long running operation that was previously started by a long running API method. If $methodName is not provided, or does not match a long running API method, then the operation can still be resumed, but the OperationResponse object will not deserialize the final response.

Parameters
NameDescription
operationName string

The name of the long running operation

methodName string

The name of the method used to start the operation

Returns
TypeDescription
Google\ApiCore\OperationResponse

__construct

Constructor.

Parameters
NameDescription
options array

Optional. Options for configuring the service API wrapper.

↳ apiEndpoint string

The address of the API remote host. May optionally include the port, formatted as "

↳ credentials string|array|FetchAuthTokenInterface|CredentialsWrapper

The credentials to be used by the client to authorize API calls. This option accepts either a path to a credentials file, or a decoded credentials file as a PHP array. Advanced usage: In addition, this option can also accept a pre-constructed Google\Auth\FetchAuthTokenInterface object or Google\ApiCore\CredentialsWrapper object. Note that when one of these objects are provided, any settings in $credentialsConfig will be ignored.

↳ credentialsConfig array

Options used to configure credentials, including auth token caching, for the client. For a full list of supporting configuration options, see Google\ApiCore\CredentialsWrapper::build() .

↳ disableRetries bool

Determines whether or not retries defined by the client configuration should be disabled. Defaults to false.

↳ clientConfig string|array

Client method configuration, including retry settings. This option can be either a path to a JSON file, or a PHP array containing the decoded JSON data. By default this settings points to the default client config file, which is provided in the resources folder.

↳ transport string|TransportInterface

The transport used for executing network requests. May be either the string rest or grpc. Defaults to grpc if gRPC support is detected on the system. Advanced usage: Additionally, it is possible to pass in an already instantiated Google\ApiCore\Transport\TransportInterface object. Note that when this object is provided, any settings in $transportConfig, and any $apiEndpoint setting, will be ignored.

↳ transportConfig array

Configuration options that will be used to construct the transport. Options for each supported transport type should be passed in a key for that transport. For example: $transportConfig = [ 'grpc' => [...], 'rest' => [...], ]; See the Google\ApiCore\Transport\GrpcTransport::build() and Google\ApiCore\Transport\RestTransport::build() methods for the supported options.

↳ clientCertSource callable

A callable which returns the client cert as a string. This can be used to provide a certificate and private key to the transport layer for mTLS.

copyBackup

Starts copying a Cloud Spanner Backup.

The returned backup long-running operation will have a name of the format projects/<project>/instances/<instance>/backups/<backup>/operations/<operation_id> and can be used to track copying of the backup. The operation is associated with the destination backup. The metadata field type is CopyBackupMetadata. The response field type is Backup, if successful. Cancelling the returned operation will stop the copying and delete the backup. Concurrent CopyBackup requests can run on the same source backup.

Sample code:

$databaseAdminClient = new DatabaseAdminClient();
try {
    $formattedParent = $databaseAdminClient->instanceName('[PROJECT]', '[INSTANCE]');
    $backupId = 'backup_id';
    $formattedSourceBackup = $databaseAdminClient->backupName('[PROJECT]', '[INSTANCE]', '[BACKUP]');
    $expireTime = new Timestamp();
    $operationResponse = $databaseAdminClient->copyBackup($formattedParent, $backupId, $formattedSourceBackup, $expireTime);
    $operationResponse->pollUntilComplete();
    if ($operationResponse->operationSucceeded()) {
        $result = $operationResponse->getResult();
    // doSomethingWith($result)
    } else {
        $error = $operationResponse->getError();
        // handleError($error)
    }
    // Alternatively:
    // start the operation, keep the operation name, and resume later
    $operationResponse = $databaseAdminClient->copyBackup($formattedParent, $backupId, $formattedSourceBackup, $expireTime);
    $operationName = $operationResponse->getName();
    // ... do other work
    $newOperationResponse = $databaseAdminClient->resumeOperation($operationName, 'copyBackup');
    while (!$newOperationResponse->isDone()) {
        // ... do other work
        $newOperationResponse->reload();
    }
    if ($newOperationResponse->operationSucceeded()) {
        $result = $newOperationResponse->getResult();
    // doSomethingWith($result)
    } else {
        $error = $newOperationResponse->getError();
        // handleError($error)
    }
} finally {
    $databaseAdminClient->close();
}
Parameters
NameDescription
parent string

Required. The name of the destination instance that will contain the backup copy. Values are of the form: projects/<project>/instances/<instance>.

backupId string

Required. The id of the backup copy. The backup_id appended to parent forms the full backup_uri of the form projects/<project>/instances/<instance>/backups/<backup>.

sourceBackup string

Required. The source backup to be copied. The source backup needs to be in READY state for it to be copied. Once CopyBackup is in progress, the source backup cannot be deleted or cleaned up on expiration until CopyBackup is finished. Values are of the form: projects/<project>/instances/<instance>/backups/<backup>.

expireTime Google\Protobuf\Timestamp

Required. The expiration time of the backup in microsecond granularity. The expiration time must be at least 6 hours and at most 366 days from the create_time of the source backup. Once the expire_time has passed, the backup is eligible to be automatically deleted by Cloud Spanner to free the resources used by the backup.

optionalArgs array

Optional.

↳ encryptionConfig CopyBackupEncryptionConfig

Optional. The encryption configuration used to encrypt the backup. If this field is not specified, the backup will use the same encryption configuration as the source backup by default, namely encryption_type = USE_CONFIG_DEFAULT_OR_BACKUP_ENCRYPTION.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\OperationResponse

createBackup

Starts creating a new Cloud Spanner Backup.

The returned backup long-running operation will have a name of the format projects/<project>/instances/<instance>/backups/<backup>/operations/<operation_id> and can be used to track creation of the backup. The metadata field type is CreateBackupMetadata. The response field type is Backup, if successful. Cancelling the returned operation will stop the creation and delete the backup. There can be only one pending backup creation per database. Backup creation of different databases can run concurrently.

Sample code:

$databaseAdminClient = new DatabaseAdminClient();
try {
    $formattedParent = $databaseAdminClient->instanceName('[PROJECT]', '[INSTANCE]');
    $backupId = 'backup_id';
    $backup = new Backup();
    $operationResponse = $databaseAdminClient->createBackup($formattedParent, $backupId, $backup);
    $operationResponse->pollUntilComplete();
    if ($operationResponse->operationSucceeded()) {
        $result = $operationResponse->getResult();
    // doSomethingWith($result)
    } else {
        $error = $operationResponse->getError();
        // handleError($error)
    }
    // Alternatively:
    // start the operation, keep the operation name, and resume later
    $operationResponse = $databaseAdminClient->createBackup($formattedParent, $backupId, $backup);
    $operationName = $operationResponse->getName();
    // ... do other work
    $newOperationResponse = $databaseAdminClient->resumeOperation($operationName, 'createBackup');
    while (!$newOperationResponse->isDone()) {
        // ... do other work
        $newOperationResponse->reload();
    }
    if ($newOperationResponse->operationSucceeded()) {
        $result = $newOperationResponse->getResult();
    // doSomethingWith($result)
    } else {
        $error = $newOperationResponse->getError();
        // handleError($error)
    }
} finally {
    $databaseAdminClient->close();
}
Parameters
NameDescription
parent string

Required. The name of the instance in which the backup will be created. This must be the same instance that contains the database the backup will be created from. The backup will be stored in the location(s) specified in the instance configuration of this instance. Values are of the form projects/<project>/instances/<instance>.

backupId string

Required. The id of the backup to be created. The backup_id appended to parent forms the full backup name of the form projects/<project>/instances/<instance>/backups/<backup_id>.

backup Google\Cloud\Spanner\Admin\Database\V1\Backup

Required. The backup to create.

optionalArgs array

Optional.

↳ encryptionConfig CreateBackupEncryptionConfig

Optional. The encryption configuration used to encrypt the backup. If this field is not specified, the backup will use the same encryption configuration as the database by default, namely encryption_type = USE_DATABASE_ENCRYPTION.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\OperationResponse

createDatabase

Creates a new Cloud Spanner database and starts to prepare it for serving.

The returned long-running operation will have a name of the format <database_name>/operations/<operation_id> and can be used to track preparation of the database. The metadata field type is CreateDatabaseMetadata. The response field type is Database, if successful.

Sample code:

$databaseAdminClient = new DatabaseAdminClient();
try {
    $formattedParent = $databaseAdminClient->instanceName('[PROJECT]', '[INSTANCE]');
    $createStatement = 'create_statement';
    $operationResponse = $databaseAdminClient->createDatabase($formattedParent, $createStatement);
    $operationResponse->pollUntilComplete();
    if ($operationResponse->operationSucceeded()) {
        $result = $operationResponse->getResult();
    // doSomethingWith($result)
    } else {
        $error = $operationResponse->getError();
        // handleError($error)
    }
    // Alternatively:
    // start the operation, keep the operation name, and resume later
    $operationResponse = $databaseAdminClient->createDatabase($formattedParent, $createStatement);
    $operationName = $operationResponse->getName();
    // ... do other work
    $newOperationResponse = $databaseAdminClient->resumeOperation($operationName, 'createDatabase');
    while (!$newOperationResponse->isDone()) {
        // ... do other work
        $newOperationResponse->reload();
    }
    if ($newOperationResponse->operationSucceeded()) {
        $result = $newOperationResponse->getResult();
    // doSomethingWith($result)
    } else {
        $error = $newOperationResponse->getError();
        // handleError($error)
    }
} finally {
    $databaseAdminClient->close();
}
Parameters
NameDescription
parent string

Required. The name of the instance that will serve the new database. Values are of the form projects/<project>/instances/<instance>.

createStatement string

Required. A CREATE DATABASE statement, which specifies the ID of the new database. The database ID must conform to the regular expression [a-z][a-z0-9_\-]*[a-z0-9] and be between 2 and 30 characters in length. If the database ID is a reserved word or if it contains a hyphen, the database ID must be enclosed in backticks (` ).

optionalArgs array

Optional.

↳ extraStatements string[]

Optional. A list of DDL statements to run inside the newly created database. Statements can create tables, indexes, etc. These statements execute atomically with the creation of the database: if there is an error in any statement, the database is not created.

↳ encryptionConfig EncryptionConfig

Optional. The encryption configuration for the database. If this field is not specified, Cloud Spanner will encrypt/decrypt all data at rest using Google default encryption.

↳ databaseDialect int

Optional. The dialect of the Cloud Spanner Database. For allowed values, use constants defined on Google\Cloud\Spanner\Admin\Database\V1\DatabaseDialect

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\OperationResponse

deleteBackup

Deletes a pending or completed Backup.

Sample code:

$databaseAdminClient = new DatabaseAdminClient();
try {
    $formattedName = $databaseAdminClient->backupName('[PROJECT]', '[INSTANCE]', '[BACKUP]');
    $databaseAdminClient->deleteBackup($formattedName);
} finally {
    $databaseAdminClient->close();
}
Parameters
NameDescription
name string

Required. Name of the backup to delete. Values are of the form projects/<project>/instances/<instance>/backups/<backup>.

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

dropDatabase

Drops (aka deletes) a Cloud Spanner database.

Completed backups for the database will be retained according to their expire_time. Note: Cloud Spanner might continue to accept requests for a few seconds after the database has been deleted.

Sample code:

$databaseAdminClient = new DatabaseAdminClient();
try {
    $formattedDatabase = $databaseAdminClient->databaseName('[PROJECT]', '[INSTANCE]', '[DATABASE]');
    $databaseAdminClient->dropDatabase($formattedDatabase);
} finally {
    $databaseAdminClient->close();
}
Parameters
NameDescription
database string

Required. The database to be dropped.

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

getBackup

Gets metadata on a pending or completed Backup.

Sample code:

$databaseAdminClient = new DatabaseAdminClient();
try {
    $formattedName = $databaseAdminClient->backupName('[PROJECT]', '[INSTANCE]', '[BACKUP]');
    $response = $databaseAdminClient->getBackup($formattedName);
} finally {
    $databaseAdminClient->close();
}
Parameters
NameDescription
name string

Required. Name of the backup. Values are of the form projects/<project>/instances/<instance>/backups/<backup>.

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\Spanner\Admin\Database\V1\Backup

getDatabase

Gets the state of a Cloud Spanner database.

Sample code:

$databaseAdminClient = new DatabaseAdminClient();
try {
    $formattedName = $databaseAdminClient->databaseName('[PROJECT]', '[INSTANCE]', '[DATABASE]');
    $response = $databaseAdminClient->getDatabase($formattedName);
} finally {
    $databaseAdminClient->close();
}
Parameters
NameDescription
name string

Required. The name of the requested database. Values are of the form projects/<project>/instances/<instance>/databases/<database>.

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\Spanner\Admin\Database\V1\Database

getDatabaseDdl

Returns the schema of a Cloud Spanner database as a list of formatted DDL statements. This method does not show pending schema updates, those may be queried using the Operations API.

Sample code:

$databaseAdminClient = new DatabaseAdminClient();
try {
    $formattedDatabase = $databaseAdminClient->databaseName('[PROJECT]', '[INSTANCE]', '[DATABASE]');
    $response = $databaseAdminClient->getDatabaseDdl($formattedDatabase);
} finally {
    $databaseAdminClient->close();
}
Parameters
NameDescription
database string

Required. The database whose schema we wish to get. Values are of the form projects/<project>/instances/<instance>/databases/<database>

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\Spanner\Admin\Database\V1\GetDatabaseDdlResponse

getIamPolicy

Gets the access control policy for a database or backup resource.

Returns an empty policy if a database or backup exists but does not have a policy set.

Authorization requires spanner.databases.getIamPolicy permission on resource. For backups, authorization requires spanner.backups.getIamPolicy permission on resource.

Sample code:

$databaseAdminClient = new DatabaseAdminClient();
try {
    $resource = 'resource';
    $response = $databaseAdminClient->getIamPolicy($resource);
} finally {
    $databaseAdminClient->close();
}
Parameters
NameDescription
resource string

REQUIRED: The resource for which the policy is being requested. See the operation documentation for the appropriate value for this field.

optionalArgs array

Optional.

↳ options GetPolicyOptions

OPTIONAL: A GetPolicyOptions object for specifying options to GetIamPolicy.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\Iam\V1\Policy

listBackupOperations

Lists the backup long-running operations in the given instance. A backup operation has a name of the form projects/<project>/instances/<instance>/backups/<backup>/operations/<operation>.

The long-running operation metadata field type metadata.type_url describes the type of the metadata. Operations returned include those that have completed/failed/canceled within the last 7 days, and pending operations. Operations returned are ordered by operation.metadata.value.progress.start_time in descending order starting from the most recently started operation.

Sample code:

$databaseAdminClient = new DatabaseAdminClient();
try {
    $formattedParent = $databaseAdminClient->instanceName('[PROJECT]', '[INSTANCE]');
    // Iterate over pages of elements
    $pagedResponse = $databaseAdminClient->listBackupOperations($formattedParent);
    foreach ($pagedResponse->iteratePages() as $page) {
        foreach ($page as $element) {
            // doSomethingWith($element);
        }
    }
    // Alternatively:
    // Iterate through all elements
    $pagedResponse = $databaseAdminClient->listBackupOperations($formattedParent);
    foreach ($pagedResponse->iterateAllElements() as $element) {
        // doSomethingWith($element);
    }
} finally {
    $databaseAdminClient->close();
}
Parameters
NameDescription
parent string

Required. The instance of the backup operations. Values are of the form projects/<project>/instances/<instance>.

optionalArgs array

Optional.

↳ filter string

An expression that filters the list of returned backup operations. A filter expression consists of a field name, a comparison operator, and a value for filtering. The value must be a string, a number, or a boolean. The comparison operator must be one of: <, >, <=, >=, !=, =, or :. Colon : is the contains operator. Filter rules are not case sensitive. The following fields in the operation are eligible for filtering: * name - The name of the long-running operation * done - False if the operation is in progress, else true. * metadata.@type - the type of metadata. For example, the type string for CreateBackupMetadata is type.googleapis.com/google.spanner.admin.database.v1.CreateBackupMetadata. * metadata.<field_name> - any field in metadata.value. metadata.@type must be specified first if filtering on metadata fields. * error - Error associated with the long-running operation. * response.@type - the type of response. * response.<field_name> - any field in response.value. You can combine multiple expressions by enclosing each expression in parentheses. By default, expressions are combined with AND logic, but you can specify AND, OR, and NOT logic explicitly. Here are a few examples: * done:true - The operation is complete. * (metadata.@type=type.googleapis.com/google.spanner.admin.database.v1.CreateBackupMetadata) AND \ metadata.database:prod - Returns operations where: * The operation's metadata type is CreateBackupMetadata. * The database the backup was taken from has a name containing the string "prod". * (metadata.@type=type.googleapis.com/google.spanner.admin.database.v1.CreateBackupMetadata) AND \ (metadata.name:howl) AND \ (metadata.progress.start_time < \"2018-03-28T14:50:00Z\") AND \ (error:*) - Returns operations where: * The operation's metadata type is CreateBackupMetadata. * The backup name contains the string "howl". * The operation started before 2018-03-28T14:50:00Z. * The operation resulted in an error. * (metadata.@type=type.googleapis.com/google.spanner.admin.database.v1.CopyBackupMetadata) AND \ (metadata.source_backup:test) AND \ (metadata.progress.start_time < \"2022-01-18T14:50:00Z\") AND \ (error:*) - Returns operations where: * The operation's metadata type is CopyBackupMetadata. * The source backup of the copied backup name contains the string "test". * The operation started before 2022-01-18T14:50:00Z. * The operation resulted in an error. * ((metadata.@type=type.googleapis.com/google.spanner.admin.database.v1.CreateBackupMetadata) AND \ (metadata.database:test_db)) OR \ ((metadata.@type=type.googleapis.com/google.spanner.admin.database.v1.CopyBackupMetadata) AND \ (metadata.source_backup:test_bkp)) AND \ (error:*) - Returns operations where: * The operation's metadata matches either of criteria: * The operation's metadata type is CreateBackupMetadata AND the database the backup was taken from has name containing string "test_db" * The operation's metadata type is CopyBackupMetadata AND the backup the backup was copied from has name containing string "test_bkp" * The operation resulted in an error.

↳ pageSize int

The maximum number of resources contained in the underlying API response. The API may return fewer values in a page, even if there are additional values to be retrieved.

↳ pageToken string

A page token is used to specify a page of values to be returned. If no page token is specified (the default), the first page of values will be returned. Any page token used here must have been generated by a previous call to the API.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\PagedListResponse

listBackups

Lists completed and pending backups.

Backups returned are ordered by create_time in descending order, starting from the most recent create_time.

Sample code:

$databaseAdminClient = new DatabaseAdminClient();
try {
    $formattedParent = $databaseAdminClient->instanceName('[PROJECT]', '[INSTANCE]');
    // Iterate over pages of elements
    $pagedResponse = $databaseAdminClient->listBackups($formattedParent);
    foreach ($pagedResponse->iteratePages() as $page) {
        foreach ($page as $element) {
            // doSomethingWith($element);
        }
    }
    // Alternatively:
    // Iterate through all elements
    $pagedResponse = $databaseAdminClient->listBackups($formattedParent);
    foreach ($pagedResponse->iterateAllElements() as $element) {
        // doSomethingWith($element);
    }
} finally {
    $databaseAdminClient->close();
}
Parameters
NameDescription
parent string

Required. The instance to list backups from. Values are of the form projects/<project>/instances/<instance>.

optionalArgs array

Optional.

↳ filter string

An expression that filters the list of returned backups. A filter expression consists of a field name, a comparison operator, and a value for filtering. The value must be a string, a number, or a boolean. The comparison operator must be one of: <, >, <=, >=, !=, =, or :. Colon : is the contains operator. Filter rules are not case sensitive. The following fields in the Backup are eligible for filtering: * name * database * state * create_time (and values are of the format YYYY-MM-DDTHH:MM:SSZ) * expire_time (and values are of the format YYYY-MM-DDTHH:MM:SSZ) * version_time (and values are of the format YYYY-MM-DDTHH:MM:SSZ) * size_bytes You can combine multiple expressions by enclosing each expression in parentheses. By default, expressions are combined with AND logic, but you can specify AND, OR, and NOT logic explicitly. Here are a few examples: * name:Howl - The backup's name contains the string "howl". * database:prod - The database's name contains the string "prod". * state:CREATING - The backup is pending creation. * state:READY - The backup is fully created and ready for use. * (name:howl) AND (create_time < \"2018-03-28T14:50:00Z\") - The backup name contains the string "howl" and create_time of the backup is before 2018-03-28T14:50:00Z. * expire_time < \"2018-03-28T14:50:00Z\" - The backup expire_time is before 2018-03-28T14:50:00Z. * size_bytes > 10000000000 - The backup's size is greater than 10GB

↳ pageSize int

The maximum number of resources contained in the underlying API response. The API may return fewer values in a page, even if there are additional values to be retrieved.

↳ pageToken string

A page token is used to specify a page of values to be returned. If no page token is specified (the default), the first page of values will be returned. Any page token used here must have been generated by a previous call to the API.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\PagedListResponse

listDatabaseOperations

Lists database longrunning-operations.

A database operation has a name of the form projects/<project>/instances/<instance>/databases/<database>/operations/<operation>. The long-running operation metadata field type metadata.type_url describes the type of the metadata. Operations returned include those that have completed/failed/canceled within the last 7 days, and pending operations.

Sample code:

$databaseAdminClient = new DatabaseAdminClient();
try {
    $formattedParent = $databaseAdminClient->instanceName('[PROJECT]', '[INSTANCE]');
    // Iterate over pages of elements
    $pagedResponse = $databaseAdminClient->listDatabaseOperations($formattedParent);
    foreach ($pagedResponse->iteratePages() as $page) {
        foreach ($page as $element) {
            // doSomethingWith($element);
        }
    }
    // Alternatively:
    // Iterate through all elements
    $pagedResponse = $databaseAdminClient->listDatabaseOperations($formattedParent);
    foreach ($pagedResponse->iterateAllElements() as $element) {
        // doSomethingWith($element);
    }
} finally {
    $databaseAdminClient->close();
}
Parameters
NameDescription
parent string

Required. The instance of the database operations. Values are of the form projects/<project>/instances/<instance>.

optionalArgs array

Optional.

↳ filter string

An expression that filters the list of returned operations. A filter expression consists of a field name, a comparison operator, and a value for filtering. The value must be a string, a number, or a boolean. The comparison operator must be one of: <, >, <=, >=, !=, =, or :. Colon : is the contains operator. Filter rules are not case sensitive. The following fields in the Operation are eligible for filtering: * name - The name of the long-running operation * done - False if the operation is in progress, else true. * metadata.@type - the type of metadata. For example, the type string for RestoreDatabaseMetadata is type.googleapis.com/google.spanner.admin.database.v1.RestoreDatabaseMetadata. * metadata.<field_name> - any field in metadata.value. metadata.@type must be specified first, if filtering on metadata fields. * error - Error associated with the long-running operation. * response.@type - the type of response. * response.<field_name> - any field in response.value. You can combine multiple expressions by enclosing each expression in parentheses. By default, expressions are combined with AND logic. However, you can specify AND, OR, and NOT logic explicitly. Here are a few examples: * done:true - The operation is complete. * (metadata.@type=type.googleapis.com/google.spanner.admin.database.v1.RestoreDatabaseMetadata) AND \ (metadata.source_type:BACKUP) AND \ (metadata.backup_info.backup:backup_howl) AND \ (metadata.name:restored_howl) AND \ (metadata.progress.start_time < \"2018-03-28T14:50:00Z\") AND \ (error:*) - Return operations where: * The operation's metadata type is RestoreDatabaseMetadata. * The database is restored from a backup. * The backup name contains "backup_howl". * The restored database's name contains "restored_howl". * The operation started before 2018-03-28T14:50:00Z. * The operation resulted in an error.

↳ pageSize int

The maximum number of resources contained in the underlying API response. The API may return fewer values in a page, even if there are additional values to be retrieved.

↳ pageToken string

A page token is used to specify a page of values to be returned. If no page token is specified (the default), the first page of values will be returned. Any page token used here must have been generated by a previous call to the API.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\PagedListResponse

listDatabaseRoles

Lists Cloud Spanner database roles.

Sample code:

$databaseAdminClient = new DatabaseAdminClient();
try {
    $formattedParent = $databaseAdminClient->databaseName('[PROJECT]', '[INSTANCE]', '[DATABASE]');
    // Iterate over pages of elements
    $pagedResponse = $databaseAdminClient->listDatabaseRoles($formattedParent);
    foreach ($pagedResponse->iteratePages() as $page) {
        foreach ($page as $element) {
            // doSomethingWith($element);
        }
    }
    // Alternatively:
    // Iterate through all elements
    $pagedResponse = $databaseAdminClient->listDatabaseRoles($formattedParent);
    foreach ($pagedResponse->iterateAllElements() as $element) {
        // doSomethingWith($element);
    }
} finally {
    $databaseAdminClient->close();
}
Parameters
NameDescription
parent string

Required. The database whose roles should be listed. Values are of the form projects/<project>/instances/<instance>/databases/<database>/databaseRoles.

optionalArgs array

Optional.

↳ pageSize int

The maximum number of resources contained in the underlying API response. The API may return fewer values in a page, even if there are additional values to be retrieved.

↳ pageToken string

A page token is used to specify a page of values to be returned. If no page token is specified (the default), the first page of values will be returned. Any page token used here must have been generated by a previous call to the API.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\PagedListResponse

listDatabases

Lists Cloud Spanner databases.

Sample code:

$databaseAdminClient = new DatabaseAdminClient();
try {
    $formattedParent = $databaseAdminClient->instanceName('[PROJECT]', '[INSTANCE]');
    // Iterate over pages of elements
    $pagedResponse = $databaseAdminClient->listDatabases($formattedParent);
    foreach ($pagedResponse->iteratePages() as $page) {
        foreach ($page as $element) {
            // doSomethingWith($element);
        }
    }
    // Alternatively:
    // Iterate through all elements
    $pagedResponse = $databaseAdminClient->listDatabases($formattedParent);
    foreach ($pagedResponse->iterateAllElements() as $element) {
        // doSomethingWith($element);
    }
} finally {
    $databaseAdminClient->close();
}
Parameters
NameDescription
parent string

Required. The instance whose databases should be listed. Values are of the form projects/<project>/instances/<instance>.

optionalArgs array

Optional.

↳ pageSize int

The maximum number of resources contained in the underlying API response. The API may return fewer values in a page, even if there are additional values to be retrieved.

↳ pageToken string

A page token is used to specify a page of values to be returned. If no page token is specified (the default), the first page of values will be returned. Any page token used here must have been generated by a previous call to the API.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\PagedListResponse

restoreDatabase

Create a new database by restoring from a completed backup. The new database must be in the same project and in an instance with the same instance configuration as the instance containing the backup. The returned database long-running operation has a name of the format projects/<project>/instances/<instance>/databases/<database>/operations/<operation_id>, and can be used to track the progress of the operation, and to cancel it.

The metadata field type is RestoreDatabaseMetadata. The response type is Database, if successful. Cancelling the returned operation will stop the restore and delete the database. There can be only one database being restored into an instance at a time. Once the restore operation completes, a new restore operation can be initiated, without waiting for the optimize operation associated with the first restore to complete.

Sample code:

$databaseAdminClient = new DatabaseAdminClient();
try {
    $formattedParent = $databaseAdminClient->instanceName('[PROJECT]', '[INSTANCE]');
    $databaseId = 'database_id';
    $operationResponse = $databaseAdminClient->restoreDatabase($formattedParent, $databaseId);
    $operationResponse->pollUntilComplete();
    if ($operationResponse->operationSucceeded()) {
        $result = $operationResponse->getResult();
    // doSomethingWith($result)
    } else {
        $error = $operationResponse->getError();
        // handleError($error)
    }
    // Alternatively:
    // start the operation, keep the operation name, and resume later
    $operationResponse = $databaseAdminClient->restoreDatabase($formattedParent, $databaseId);
    $operationName = $operationResponse->getName();
    // ... do other work
    $newOperationResponse = $databaseAdminClient->resumeOperation($operationName, 'restoreDatabase');
    while (!$newOperationResponse->isDone()) {
        // ... do other work
        $newOperationResponse->reload();
    }
    if ($newOperationResponse->operationSucceeded()) {
        $result = $newOperationResponse->getResult();
    // doSomethingWith($result)
    } else {
        $error = $newOperationResponse->getError();
        // handleError($error)
    }
} finally {
    $databaseAdminClient->close();
}
Parameters
NameDescription
parent string

Required. The name of the instance in which to create the restored database. This instance must be in the same project and have the same instance configuration as the instance containing the source backup. Values are of the form projects/<project>/instances/<instance>.

databaseId string

Required. The id of the database to create and restore to. This database must not already exist. The database_id appended to parent forms the full database name of the form projects/<project>/instances/<instance>/databases/<database_id>.

optionalArgs array

Optional.

↳ backup string

Name of the backup from which to restore. Values are of the form projects/<project>/instances/<instance>/backups/<backup>.

↳ encryptionConfig RestoreDatabaseEncryptionConfig

Optional. An encryption configuration describing the encryption type and key resources in Cloud KMS used to encrypt/decrypt the database to restore to. If this field is not specified, the restored database will use the same encryption configuration as the backup by default, namely encryption_type = USE_CONFIG_DEFAULT_OR_BACKUP_ENCRYPTION.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\OperationResponse

setIamPolicy

Sets the access control policy on a database or backup resource.

Replaces any existing policy.

Authorization requires spanner.databases.setIamPolicy permission on resource. For backups, authorization requires spanner.backups.setIamPolicy permission on resource.

Sample code:

$databaseAdminClient = new DatabaseAdminClient();
try {
    $resource = 'resource';
    $policy = new Policy();
    $response = $databaseAdminClient->setIamPolicy($resource, $policy);
} finally {
    $databaseAdminClient->close();
}
Parameters
NameDescription
resource string

REQUIRED: The resource for which the policy is being specified. See the operation documentation for the appropriate value for this field.

policy Google\Cloud\Iam\V1\Policy

REQUIRED: The complete policy to be applied to the resource. The size of the policy is limited to a few 10s of KB. An empty policy is a valid policy but certain Cloud Platform services (such as Projects) might reject them.

optionalArgs array

Optional.

↳ updateMask FieldMask

OPTIONAL: A FieldMask specifying which fields of the policy to modify. Only the fields in the mask will be modified. If no mask is provided, the following default mask is used: paths: "bindings, etag"

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\Iam\V1\Policy

testIamPermissions

Returns permissions that the caller has on the specified database or backup resource.

Attempting this RPC on a non-existent Cloud Spanner database will result in a NOT_FOUND error if the user has spanner.databases.list permission on the containing Cloud Spanner instance. Otherwise returns an empty set of permissions. Calling this method on a backup that does not exist will result in a NOT_FOUND error if the user has spanner.backups.list permission on the containing instance.

Sample code:

$databaseAdminClient = new DatabaseAdminClient();
try {
    $resource = 'resource';
    $permissions = [];
    $response = $databaseAdminClient->testIamPermissions($resource, $permissions);
} finally {
    $databaseAdminClient->close();
}
Parameters
NameDescription
resource string

REQUIRED: The resource for which the policy detail is being requested. See the operation documentation for the appropriate value for this field.

permissions string[]

The set of permissions to check for the resource. Permissions with wildcards (such as '' or 'storage.') are not allowed. For more information see IAM Overview.

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\Iam\V1\TestIamPermissionsResponse

updateBackup

Updates a pending or completed Backup.

Sample code:

$databaseAdminClient = new DatabaseAdminClient();
try {
    $backup = new Backup();
    $updateMask = new FieldMask();
    $response = $databaseAdminClient->updateBackup($backup, $updateMask);
} finally {
    $databaseAdminClient->close();
}
Parameters
NameDescription
backup Google\Cloud\Spanner\Admin\Database\V1\Backup

Required. The backup to update. backup.name, and the fields to be updated as specified by update_mask are required. Other fields are ignored. Update is only supported for the following fields:

  • backup.expire_time.
updateMask Google\Protobuf\FieldMask

Required. A mask specifying which fields (e.g. expire_time) in the Backup resource should be updated. This mask is relative to the Backup resource, not to the request message. The field mask must always be specified; this prevents any future fields from being erased accidentally by clients that do not know about them.

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\Spanner\Admin\Database\V1\Backup

updateDatabaseDdl

Updates the schema of a Cloud Spanner database by creating/altering/dropping tables, columns, indexes, etc. The returned long-running operation will have a name of the format <database_name>/operations/<operation_id> and can be used to track execution of the schema change(s). The metadata field type is UpdateDatabaseDdlMetadata. The operation has no response.

Sample code:

$databaseAdminClient = new DatabaseAdminClient();
try {
    $formattedDatabase = $databaseAdminClient->databaseName('[PROJECT]', '[INSTANCE]', '[DATABASE]');
    $statements = [];
    $operationResponse = $databaseAdminClient->updateDatabaseDdl($formattedDatabase, $statements);
    $operationResponse->pollUntilComplete();
    if ($operationResponse->operationSucceeded()) {
        // operation succeeded and returns no value
    } else {
        $error = $operationResponse->getError();
        // handleError($error)
    }
    // Alternatively:
    // start the operation, keep the operation name, and resume later
    $operationResponse = $databaseAdminClient->updateDatabaseDdl($formattedDatabase, $statements);
    $operationName = $operationResponse->getName();
    // ... do other work
    $newOperationResponse = $databaseAdminClient->resumeOperation($operationName, 'updateDatabaseDdl');
    while (!$newOperationResponse->isDone()) {
        // ... do other work
        $newOperationResponse->reload();
    }
    if ($newOperationResponse->operationSucceeded()) {
        // operation succeeded and returns no value
    } else {
        $error = $newOperationResponse->getError();
        // handleError($error)
    }
} finally {
    $databaseAdminClient->close();
}
Parameters
NameDescription
database string

Required. The database to update.

statements string[]

Required. DDL statements to be applied to the database.

optionalArgs array

Optional.

↳ operationId string

If empty, the new update request is assigned an automatically-generated operation ID. Otherwise, operation_id is used to construct the name of the resulting Operation. Specifying an explicit operation ID simplifies determining whether the statements were executed in the event that the UpdateDatabaseDdl call is replayed, or the return value is otherwise lost: the database and operation_id fields can be combined to form the name of the resulting longrunning.Operation: <database>/operations/<operation_id>. operation_id should be unique within the database, and must be a valid identifier: [a-z][a-z0-9_]*. Note that automatically-generated operation IDs always begin with an underscore. If the named operation already exists, UpdateDatabaseDdl returns ALREADY_EXISTS.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\OperationResponse

Constants

SERVICE_NAME

Value: 'google.spanner.admin.database.v1.DatabaseAdmin'

The name of the service.

SERVICE_ADDRESS

Value: 'spanner.googleapis.com'

The default address of the service.

DEFAULT_SERVICE_PORT

Value: 443

The default port of the service.

CODEGEN_NAME

Value: 'gapic'

The name of the code generator, to be included in the agent header.