Backup

Backup

The Backup class represents a Cloud Spanner backup.

Create a Backup object to interact with or create a Cloud Spanner backup.

Constructor

new Backup()

Example
const {Spanner} = require('@google-cloud/spanner');
const spanner = new Spanner();
const instance = spanner.instance('my-instance');
const backup = instance.backup('my-backup');

Methods

create(options, callbackopt) → {Promise.<CreateBackupResponse>}

Create a backup.

Parameters:
Name Type Attributes Description
options CreateBackupOptions

Parameters for creating a backup.

Properties
Name Type Attributes Description
gaxOptions CallOptions <optional>

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

callback CreateBackupCallback <optional>

Callback function.

Example
const {Spanner} = require('@google-cloud/spanner');
const spanner = new Spanner();
const instance = spanner.instance('my-instance');
const oneDay = 1000 * 60 * 60 * 24;
const expireTime = Date.now() + oneDay;
const backup = instance.backup('my-backup');
const [, backupOperation] = await backup.create({
  databasePath: 'projects/my-project/instances/my-instance/databases/my-database',
  expireTime: expireTime,
});
// Await completion of the backup operation.
await backupOperation.promise();

delete(gaxOptionsopt, callbackopt) → {Promise.<void>}

Deletes a backup.

Parameters:
Name Type Attributes Description
gaxOptions object <optional>

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

callback DeleteBackupCallback <optional>

Callback function.

Example
const {Spanner} = require('@google-cloud/spanner');
const spanner = new Spanner();
const instance = spanner.instance('my-instance');
const backup = instance.backup('my-backup');
await backup.delete();

exists() → {Promise.<boolean>}

Checks whether the backup exists.

See:
  • #getMetadata
Example
const {Spanner} = require('@google-cloud/spanner');
const spanner = new Spanner();
const instance = spanner.instance('my-instance');
const backup = instance.backup('my-backup');
const alreadyExists = await backup.exists();
console.log(`Does backup exist? ${alreadyExists}`);

getExpireTime() → {Promise.<external:PreciseDate>}

Retrieves the expiry time of the backup.

See:
  • #updateExpireTime
  • #getMetadata
Example
const {Spanner} = require('@google-cloud/spanner');
const spanner = new Spanner();
const instance = spanner.instance('my-instance');
const backup = instance.backup('my-backup');
const expireTime = await backup.getExpireTime();
console.log(`Backup expires on ${expireTime.toISOString()}`);

getMetadata(gaxOptionsopt, callbackopt) → {Promise.<GetMetadataResponse>}

Retrieves backup's metadata.

Parameters:
Name Type Attributes Description
gaxOptions object <optional>

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

callback GetMetadataCallback <optional>

Callback function.

See:
  • #getState
  • #getExpireTime
Example
const {Spanner} = require('@google-cloud/spanner');
const spanner = new Spanner();
const instance = spanner.instance('my-instance');
const backup = instance.backup('my-backup');
const [backupInfo] = await backup.getMetadata();
console.log(`${backupInfo.name}: size=${backupInfo.sizeBytes}`);

getState(callbackopt) → {Promise.<(EnumKey.<typeof, databaseAdmin.spanner.admin.database.v1.Backup.State>|undefined)>}

Retrieves the state of the backup.

The backup state indicates if the backup has completed.

Parameters:
Name Type Attributes Description
callback GetStateCallback <optional>

Callback function.

See:
  • #getMetadata
Example
const {Spanner} = require('@google-cloud/spanner');
const spanner = new Spanner();
const instance = spanner.instance('my-instance');
const backup = instance.backup('my-backup');
const state = await backup.getState();
const backupCompleted = (state === 'READY');

updateExpireTime(expireTime, gaxOptionsopt, callbackopt) → {Promise.<google.spanner.admin.database.v1.IBackup>}

Sets the expiry time of a backup.

Parameters:
Name Type Attributes Description
expireTime string | number | google.protobuf.Timestamp | external:PreciseDate

The expiry time to update with.

gaxOptions object <optional>

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

callback UpdateExpireTimeCallback <optional>

Callback function.

See:
  • #getExpireTime
Example
const {Spanner} = require('@google-cloud/spanner');
const spanner = new Spanner();
const instance = spanner.instance('my-instance');
const backup = instance.backup('my-backup');
const oneDay = 1000 * 60 * 60 * 24;
const newExpireTime = Spanner.timestamp(Date.now() + oneDay);
await backup.updateExpireTime(newExpireTime);