Backup

Backup

Interact with backups like get detailed information from BigTable, create a backup, or restore a backup to a table.

Constructor

new Backup(cluster, name)

Parameters:
Name Type Description
cluster Cluster

The parent instance of this backup.

name string

Name of the backup.

Example
```
const {Bigtable} = require('@google-cloud/bigtable');
const bigtable = new Bigtable();
const instance = bigtable.instance('my-instance');
const cluster = instance.cluster('my-cluster');
const backup = cluster.backup('my-backup');
```

Members

endDate

A Date-compatible PreciseDate representing the time that the backup was finished.

expireDate

A Date-compatible PreciseDate representing the expiration time of this backup.

startDate

A Date-compatible PreciseDate representing the time that this backup was started.

Methods

create(config, callbackopt) → {void|Promise.<CreateBackupResponse>}

Starts creating a new Cloud Bigtable Backup.

The returned long-running operation can be used to track creation of the backup. Cancelling the returned operation will stop the creation and delete the backup.

Parameters:
Name Type Attributes Description
config CreateBackupConfig

Configuration object.

Properties
Name Type Attributes Description
expireTime BackupTimestamp

When the backup will be automatically deleted.

table string | Table

Table to create the backup from.

gaxOptions CallOptions <optional>

Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/CallSettings.html.

callback CreateBackupCallback <optional>

The callback function.

Properties
Name Type Attributes Description
err error <nullable>

An error returned while making this request.

backup Backup

The newly created Backup.

operation Operation

An operation object that can be used to check the status of the request.

apiResponse object

The full API response.

Returns:
Type Description
void | Promise.<CreateBackupResponse>
Example
  const {Bigtable} = require('@google-cloud/bigtable');
  const bigtable = new Bigtable();

  async function createBackup() {
    /**
     * TODO(developer): Uncomment these variables before running the sample.
     */
    // const instanceId = 'YOUR_INSTANCE_ID';
    // const tableId = 'YOUR_TABLE_ID';
    // const clusterId = 'YOUR_CLUSTER_ID';
    // const backupId = 'YOUR_BACKUP_ID';

    const instance = bigtable.instance(instanceId);
    const cluster = instance.cluster(clusterId);

    const [backup, operation] = await cluster.createBackup(backupId, {
      table: tableId,
      expireTime: new Date(Date.now() + 7 * 60 * 60 * 1000), // 7 hours from now
    });

    console.log('Started a table backup operation.');
    await operation.promise();

    console.log(`Backup "${backup.id}" is now ready for use.`);
  }

  await createBackup();

delete(gaxOptionsOrCallbackopt, callbackopt) → {void|Promise.<DeleteBackupResponse>}

Deletes this pending or completed Cloud Bigtable backup.

Parameters:
Name Type Attributes Description
gaxOptionsOrCallback CallOptions | DeleteBackupCallback <optional>
callback DeleteBackupCallback <optional>

The callback function.

Properties
Name Type Attributes Description
err error <nullable>

An error returned while making this request.

apiResponse object

The full API response.

Returns:
Type Description
void | Promise.<DeleteBackupResponse>
Example
  const {Bigtable} = require('@google-cloud/bigtable');
  const bigtable = new Bigtable();

  async function deleteBackup() {
    /**
     * TODO(developer): Uncomment these variables before running the sample.
     */
    // const instanceId = 'YOUR_INSTANCE_ID';
    // const tableId = 'YOUR_TABLE_ID';
    // const clusterId = 'YOUR_CLUSTER_ID';
    // const backupId = 'YOUR_BACKUP_ID';
    const instance = bigtable.instance(instanceId);
    const table = instance.table(tableId);
    const cluster = table.cluster(clusterId);
    const backup = cluster.backup(backupId);

    await backup.delete();
    console.log(`Backup ${backupId} was deleted successfully.`);
  }

  await deleteBackup();

exists(gaxOptionsopt, callback)

Check if a backup exists.

Parameters:
Name Type Attributes Description
gaxOptions object <optional>

Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/CallSettings.html.

callback function

The callback function.

Properties
Name Type Attributes Description
err error <nullable>

An error returned while making this request.

exists boolean

Whether the backup exists or not.

get(gaxOptionsopt, callback)

Get a backup if it exists.

Parameters:
Name Type Attributes Description
gaxOptions object <optional>

Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/CallSettings.html.

callback function

The callback function.

Properties
Name Type Attributes Description
err error <nullable>

An error returned while making this request.

backup Backup

The Backup instance.

apiResponse object

The full API response.

Example
  const {Bigtable} = require('@google-cloud/bigtable');
  const bigtable = new Bigtable();

  async function getBackup() {
    /**
     * TODO(developer): Uncomment these variables before running the sample.
     */
    // const instanceId = 'YOUR_INSTANCE_ID';
    // const tableId = 'YOUR_TABLE_ID';
    // const clusterId = 'YOUR_CLUSTER_ID';
    // const backupId = 'YOUR_BACKUP_ID';
    const instance = bigtable.instance(instanceId);
    const table = instance.table(tableId);
    const cluster = table.cluster(clusterId);

    // Create a reference to the backup before performing operations on it.
    const backup = cluster.backup(backupId);

    // Get the backup's metadata, with information such as when it will expire
    // and how big it is.
    const [metadata] = await backup.getMetadata();
    console.log(`The backup is ${metadata.sizeBytes} bytes.`);

    // Time properties have Date helpers to convert to a `PreciseDate`.
    console.log(
      `The backup will auto-delete at ${metadata.expireDate.toISOString()}`
    );
    console.log(
      `The backup finished being created at ${metadata.endTime.toISOString()}`
    );
  }

  await getBackup();

getIamPolicy(optionsopt, cbopt, policy)

Parameters:
Name Type Attributes Description
options object <optional>

Configuration object.

Properties
Name Type Attributes Description
gaxOptions object <optional>

Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/CallSettings.html.

requestedPolicyVersion number <optional>

The policy format version to be returned. Valid values are 0, 1, and 3. Requests specifying an invalid value will be rejected. Requests for policies with any conditional bindings must specify version 3. Policies without any conditional bindings may specify any valid value or leave the field unset.

cb function <optional>

The callback function.

callback.error error <nullable>

An error returned while making this request.

policy Policy

The policy.

Example
    const {Bigtable} = require('@google-cloud/bigtable');
    const bigtable = new Bigtable();
    const instance = bigtable.instance(instanceId);
    const table = instance.table(tableId);

    table
      .getIamPolicy()
      .then(result => {
        const policy = result[0];
      })
      .catch(err => {
        // Handle the error.
      });

getMetadata(gaxOptionsopt, callback)

Get a backup if it exists.

Parameters:
Name Type Attributes Description
gaxOptions object <optional>

Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/CallSettings.html.

callback function

The callback function.

Properties
Name Type Attributes Description
err error <nullable>

An error returned while making this request.

metadata object

The metadata.

apiResponse object

The full API response.

Example
  const {Bigtable} = require('@google-cloud/bigtable');
  const bigtable = new Bigtable();

  async function getBackup() {
    /**
     * TODO(developer): Uncomment these variables before running the sample.
     */
    // const instanceId = 'YOUR_INSTANCE_ID';
    // const tableId = 'YOUR_TABLE_ID';
    // const clusterId = 'YOUR_CLUSTER_ID';
    // const backupId = 'YOUR_BACKUP_ID';
    const instance = bigtable.instance(instanceId);
    const table = instance.table(tableId);
    const cluster = table.cluster(clusterId);

    // Create a reference to the backup before performing operations on it.
    const backup = cluster.backup(backupId);

    // Get the backup's metadata, with information such as when it will expire
    // and how big it is.
    const [metadata] = await backup.getMetadata();
    console.log(`The backup is ${metadata.sizeBytes} bytes.`);

    // Time properties have Date helpers to convert to a `PreciseDate`.
    console.log(
      `The backup will auto-delete at ${metadata.expireDate.toISOString()}`
    );
    console.log(
      `The backup finished being created at ${metadata.endTime.toISOString()}`
    );
  }

  await getBackup();

restore(tableId, gaxOptionsOrCallbackopt, callbackopt) → {void|Promise.<RestoreTableResponse>}

Create a new table by restoring from this completed backup.

The new table must be in the same instance as the instance containing the backup. The returned long-running operation can be used to track the progress of the operation, and to cancel it.

Parameters:
Name Type Attributes Description
tableId string

The id of the table to create and restore to. This table must not already exist.

gaxOptionsOrCallback CallOptions | RestoreTableCallback <optional>
callback RestoreTableCallback <optional>

The callback function.

Properties
Name Type Attributes Description
err error <nullable>

An error returned while making this request.

table Table

The newly created Table.

operation Operation

An operation object that can be used to check the status of the request.

apiResponse object

The full API response.

Returns:
Type Description
void | Promise.<RestoreTableResponse>
Example
  const {Bigtable} = require('@google-cloud/bigtable');
  const bigtable = new Bigtable();

  async function restoreBackup() {
    /**
     * TODO(developer): Uncomment these variables before running the sample.
     */
    // const instanceId = 'YOUR_INSTANCE_ID';
    // const tableId = 'YOUR_TABLE_ID';
    // const backupId = 'YOUR_BACKUP_ID';
    const instance = bigtable.instance(instanceId);

    // Restore a table to an instance.
    const [table, operation] = await instance.createTableFromBackup({
      table: tableId,
      backup: backupId,
    });

    await operation.promise();
    console.log(`Table restored to ${table.id} successfully.`);
  }

  await restoreBackup();

restoreTo(config, tableId, instanceopt, gaxOptionsopt, callbackopt) → {void|Promise.<RestoreTableResponse>}

Create a new table by restoring from this completed backup.

The returned long-running operation can be used to track the progress of the operation, and to cancel it.

Parameters:
Name Type Attributes Description
config RestoreTableConfig

Configuration object.

tableId string

The id of the table to create and restore to. This table must not already exist.

instance Instance | string <optional>

Instance in which the new table will be created and restored to. Instance must be in the same project as the project containing backup. If omitted the instance containing the backup will be used instead.

gaxOptions CallOptions <optional>

Request configuration options, outlined here: https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html.

callback RestoreTableCallback <optional>

The callback function.

Properties
Name Type Attributes Description
err error <nullable>

An error returned while making this request.

table Table

The newly created Table.

operation Operation

An operation object that can be used to check the status of the request.

apiResponse object

The full API response.

Returns:
Type Description
void | Promise.<RestoreTableResponse>

setIamPolicy(gaxOptionsopt, callbackopt, policy)

Parameters:
Name Type Attributes Description
gaxOptions object <optional>

Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/CallSettings.html.

callback function <optional>

The callback function.

Properties
Name Type Attributes Description
error error <nullable>

An error returned while making this request.

policy Policy

The policy.

Example
    const {Bigtable} = require('@google-cloud/bigtable');
    const bigtable = new Bigtable();
    const instance = bigtable.instance(instanceId);

    const policy = {
      bindings: [
        {
          role: 'roles/bigtable.viewer',
          members: ['user:mike@example.com', 'group:admins@example.com'],
        },
      ],
    };

    instance
      .setIamPolicy(policy)
      .then(result => {
        const setPolicy = result[0];
      })
      .catch(err => {
        // Handle the error
      });

setMetadata(metadata, gaxOptionsOrCallbackopt, callbackopt) → {void|Promise.<BackupSetMetadataResponse>}

Updates this pending or completed Cloud Bigtable Backup.

Parameters:
Name Type Attributes Description
metadata ModifiableBackupFields

The fields to be updated.

gaxOptionsOrCallback CallOptions | BackupSetMetadataCallback <optional>
callback BackupSetMetadataCallback <optional>

The callback function.

Properties
Name Type Attributes Description
err error <nullable>

An error returned while making this request.

callback.apiResponse object

The full API response.

Returns:
Type Description
void | Promise.<BackupSetMetadataResponse>
Example
  const {Bigtable} = require('@google-cloud/bigtable');
  const bigtable = new Bigtable();

  async function updateBackup() {
    /**
     * TODO(developer): Uncomment these variables before running the sample.
     */
    // const instanceId = 'YOUR_INSTANCE_ID';
    // const tableId = 'YOUR_TABLE_ID';
    // const clusterId = 'YOUR_CLUSTER_ID';
    // const backupId = 'YOUR_BACKUP_ID';
    const instance = bigtable.instance(instanceId);
    const table = instance.table(tableId);
    const cluster = table.cluster(clusterId);
    const backup = cluster.backup(backupId);

    // Extend a backup's life by updating its expiry date.
    const [metadata] = await backup.setMetadata({
      expireTime: new Date(Date.now() + 24 * 60 * 60 * 1000), // 24 hours
    });
    console.log(`The backup will now auto-delete at ${metadata.expireDate}.`);
  }

  await updateBackup();

testIamPermissions(permissions, gaxOptionsopt, callbackopt, permissions)

Parameters:
Name Type Attributes Description
permissions string | Array.<string>

The permission(s) to test for.

gaxOptions object <optional>

Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/CallSettings.html.

callback function <optional>

The callback function.

Properties
Name Type Attributes Description
error error <nullable>

An error returned while making this request.

permissions Array.<string>

A subset of permissions that the caller is allowed.

Example
    const {Bigtable} = require('@google-cloud/bigtable');
    const bigtable = new Bigtable();
    const instance = bigtable.instance(instanceId);
    const table = instance.table(tableId);

    const permissions = ['bigtable.tables.get', 'bigtable.tables.readRows'];
    table
      .testIamPermissions(permissions)
      .then(result => {
        const grantedPermissions = result[0];
      })
      .catch(err => {
        // Handle the error
      });