The Backup class represents a Cloud Spanner backup.
Create a Backup
object to interact with or create a Cloud Spanner backup.
Package
@google-cloud/spanner
Example
const {Spanner} = require('@google-cloud/spanner');
const spanner = new Spanner();
const instance = spanner.instance('my-instance');
const backup = instance.backup('my-backup');
Constructors
(constructor)(instance, name)
constructor(instance: Instance, name: string);
Constructs a new instance of the Backup
class
Parameters |
---|
Name | Description |
instance |
Instance
|
name |
string
|
Properties
id
instanceFormattedName_: string;
metadata?: databaseAdmin.spanner.admin.database.v1.IBackup;
request
resourceHeader_: {
[k: string]: string;
};
Methods
create(options)
create(options: CreateBackupOptions): Promise<CreateBackupResponse>;
Create a backup.
Backup#create
Parameter |
---|
Name | Description |
options |
CreateBackupOptions
Parameters for creating a backup.
|
Returns |
---|
Type | Description |
Promise<CreateBackupResponse> | {Promise
|
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 versionTime = 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,
versionTime: versionTime,
encryptionConfig: {
encryptionType: 'CUSTOMER_MANAGED_ENCRYPTION',
kmsKeyName: 'projects/my-project-id/my-region/keyRings/my-key-ring/cryptoKeys/my-key',
},
});
// Await completion of the backup operation.
await backupOperation.promise();
create(options, callback)
create(options: CreateBackupOptions, callback: CreateBackupCallback): void;
Parameters |
---|
Name | Description |
options |
CreateBackupOptions
|
callback |
CreateBackupCallback
|
Returns |
---|
Type | Description |
void | |
delete(gaxOptions)
delete(gaxOptions?: CallOptions): Promise<databaseAdmin.protobuf.IEmpty>;
Deletes a backup.
Backup#delete
Parameter |
---|
Name | Description |
gaxOptions |
CallOptions
Request configuration options, See CallOptions for more details.
|
Returns |
---|
Type | Description |
Promise<google.protobuf.IEmpty> | {Promise
|
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();
delete(callback)
delete(callback: DeleteCallback): void;
Parameter |
---|
Name | Description |
callback |
DeleteCallback
|
Returns |
---|
Type | Description |
void | |
delete(gaxOptions, callback)
delete(gaxOptions: CallOptions, callback: DeleteCallback): void;
Parameters |
---|
Name | Description |
gaxOptions |
CallOptions
|
callback |
DeleteCallback
|
Returns |
---|
Type | Description |
void | |
exists()
exists(): Promise<boolean>;
Checks whether the backup exists.
Returns |
---|
Type | Description |
Promise<boolean> | {Promise
|
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}`);
exists(callback)
exists(callback: ExistsCallback): void;
Parameter |
---|
Name | Description |
callback |
ExistsCallback
|
Returns |
---|
Type | Description |
void | |
static formatName_(instanceName: string, name: string): string;
Format the backup name to include the instance name.
Parameters |
---|
Name | Description |
instanceName |
string
The formatted instance name.
|
name |
string
The table name.
|
Returns |
---|
Type | Description |
string | {string}
|
Example
Backup.formatName_(
'projects/grape-spaceship-123/instances/my-instance',
'my-backup'
);
// 'projects/grape-spaceship-123/instances/my-instance/backups/my-backup'
getExpireTime()
getExpireTime(): Promise<PreciseDate | undefined>;
Retrieves the expiry time of the backup.
Returns |
---|
Type | Description |
Promise<PreciseDate | undefined> | {Promise<external:PreciseDate>} When resolved, contains the current expire time of the backup if it exists.
|
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()}`);
getExpireTime(callback)
getExpireTime(callback: GetExpireTimeCallback): void;
Parameter |
---|
Name | Description |
callback |
GetExpireTimeCallback
|
Returns |
---|
Type | Description |
void | |
getMetadata(gaxOptions?: CallOptions): Promise<GetMetadataResponse>;
Retrieves backup's metadata.
Parameter |
---|
Name | Description |
gaxOptions |
CallOptions
Request configuration options, See CallOptions for more details.
|
Returns |
---|
Type | Description |
Promise<GetMetadataResponse> | {Promise
|
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}`);
getMetadata(callback: GetMetadataCallback): void;
Parameter |
---|
Name | Description |
callback |
GetMetadataCallback
|
Returns |
---|
Type | Description |
void | |
getMetadata(gaxOptions: CallOptions, callback: GetMetadataCallback): void;
Parameters |
---|
Name | Description |
gaxOptions |
CallOptions
|
callback |
GetMetadataCallback
|
Returns |
---|
Type | Description |
void | |
getState()
getState(): Promise<EnumKey<typeof databaseAdmin.spanner.admin.database.v1.Backup.State> | undefined | null>;
Retrieves the state of the backup.
The backup state indicates if the backup has completed.
Returns |
---|
Type | Description |
Promise<EnumKey<typeof google.spanner.admin.database.v1.Backup.State> | undefined | null> | {Promise<EnumKey<typeof, databaseAdmin.spanner.admin.database.v1.Backup.State> | undefined>} When resolved, contains the current state of the backup if it exists.
|
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');
getState(callback)
getState(callback: GetStateCallback): void;
Parameter |
---|
Name | Description |
callback |
GetStateCallback
|
Returns |
---|
Type | Description |
void | |
updateExpireTime(expireTime)
updateExpireTime(expireTime: string | number | p.ITimestamp | PreciseDate): Promise<databaseAdmin.spanner.admin.database.v1.IBackup>;
Sets the expiry time of a backup.
Parameter |
---|
Name | Description |
expireTime |
string | number | common.ITimestamp | PreciseDate
The expiry time to update with.
|
Returns |
---|
Type | Description |
Promise<google.spanner.admin.database.v1.IBackup> | {Promise<google.spanner.admin.database.v1.IBackup>} When resolved, the backup's expire time will have been updated.
|
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);
updateExpireTime(expireTime, gaxOptions)
updateExpireTime(expireTime: string | number | p.ITimestamp | PreciseDate, gaxOptions?: CallOptions): Promise<databaseAdmin.spanner.admin.database.v1.IBackup>;
Parameters |
---|
Name | Description |
expireTime |
string | number | common.ITimestamp | PreciseDate
|
gaxOptions |
CallOptions
|
Returns |
---|
Type | Description |
Promise<google.spanner.admin.database.v1.IBackup> | |
updateExpireTime(expireTime, callback)
updateExpireTime(expireTime: string | number | p.ITimestamp | PreciseDate, callback: UpdateExpireTimeCallback): void;
Parameters |
---|
Name | Description |
expireTime |
string | number | common.ITimestamp | PreciseDate
|
callback |
UpdateExpireTimeCallback
|
Returns |
---|
Type | Description |
void | |
updateExpireTime(expireTime, gaxOptions, callback)
updateExpireTime(expireTime: string | number | p.ITimestamp | PreciseDate, gaxOptions: CallOptions, callback: UpdateExpireTimeCallback): void;
Parameters |
---|
Name | Description |
expireTime |
string | number | common.ITimestamp | PreciseDate
|
gaxOptions |
CallOptions
|
callback |
UpdateExpireTimeCallback
|
Returns |
---|
Type | Description |
void | |