The Backup class represents a Cloud Spanner backup.
Create a Backup
object to interact with or create a Cloud Spanner backup or copy a 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');
* @example
const {Spanner} = require('@google-cloud/spanner');
const spanner = new Spanner();
const instance = spanner.instance('my-instance');
const sourceBackup = instance.backup('my-source-backup');
const copyBackup = instance.copyBackup('my-copy-backup', 'my-source-backup');
Constructors
(constructor)(instance, name, sourceName)
constructor(instance: Instance, name: string, sourceName?: string);
Constructs a new instance of the Backup
class
Parameters |
---|
Name | Description |
instance |
Instance
|
name |
string
|
sourceName |
string
|
Properties
id
instanceFormattedName_: string;
metadata?: databaseAdmin.spanner.admin.database.v1.IBackup;
request
resourceHeader_: {
[k: string]: string;
};
sourceName
sourceName: string | undefined;
Methods
create(options)
create(options: CreateBackupOptions | CopyBackupOptions): Promise<CreateBackupResponse> | Promise<CopyBackupResponse>;
Create a backup.
Backup#create
Parameter |
---|
Name | Description |
options |
CreateBackupOptions | CopyBackupOptions
Parameters for creating a backup.
|
Returns |
---|
Type | Description |
Promise<CreateBackupResponse> | Promise<CopyBackupResponse> | {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 | CopyBackupOptions, callback: CreateBackupCallback | CopyBackupCallback): void;
Parameters |
---|
Name | Description |
options |
CreateBackupOptions | CopyBackupOptions
|
callback |
CreateBackupCallback | CopyBackupCallback
|
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.
|
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.
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.
|
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
|
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 | |