public interface DatabaseAdminClient
Client to do admin operations on a Cloud Spanner Database.
Methods
cancelOperation(String name)
public abstract void cancelOperation(String name)
Cancels the specified long-running operation.
Parameter | |
---|---|
Name | Description |
name |
String |
copyBackup(BackupId sourceBackupId, Backup destinationBackup)
public default OperationFuture<Backup,CopyBackupMetadata> copyBackup(BackupId sourceBackupId, Backup destinationBackup)
Creates a copy of backup from an existing backup in Cloud Spanner in the same instance. Any configuration options in the Backup instance will be included in the com.google.spanner.admin.database.v1.CopyBackupRequest.
The expire time of the new backup must be set and be at least 6 hours and at most 366 days after the creation time of the existing backup that is being copied.
Example to create a copy of a backup.
BackupId sourceBackupId = BackupId.of("source-project", "source-instance", "source-backup-id");
BackupId destinationBackupId = BackupId.of("destination-project", "destination-instance", "new-backup-id");
Timestamp expireTime = Timestamp.ofTimeMicroseconds(expireTimeMicros);
EncryptionConfig encryptionConfig =
EncryptionConfig.ofKey(
"projects/my-project/locations/some-location/keyRings/my-keyring/cryptoKeys/my-key"));
Backup destinationBackup = dbAdminClient
.newBackupBuilder(destinationBackupId)
.setExpireTime(expireTime)
.setEncryptionConfig(encryptionConfig)
.build();
OperationFuture<Backup, CopyBackupMetadata> op = dbAdminClient.copyBackup(sourceBackupId, destinationBackup);
Backup copiedBackup = op.get();
Parameters | |
---|---|
Name | Description |
sourceBackupId |
BackupId the backup to be copied |
destinationBackup |
Backup the new backup to create |
Returns | |
---|---|
Type | Description |
OperationFuture<Backup,CopyBackupMetadata> |
copyBackup(String instanceId, String sourceBackupId, String destinationBackupId, Timestamp expireTime)
public default OperationFuture<Backup,CopyBackupMetadata> copyBackup(String instanceId, String sourceBackupId, String destinationBackupId, Timestamp expireTime)
Creates a copy of backup from an existing backup in a Cloud Spanner instance.
Example to copy a backup.
String instanceId ="my_instance_id";
String sourceBackupId ="source_backup_id";
String destinationBackupId ="destination_backup_id";
Timestamp expireTime =Timestamp.ofTimeMicroseconds(micros);
OperationFuture<Backup, CopyBackupMetadata> op = dbAdminClient
.copyBackup(
instanceId,
sourceBackupId,
destinationBackupId,
expireTime);
Backup backup = op.get();
Parameters | |
---|---|
Name | Description |
instanceId |
String the id of the instance where the source backup is located and where the new backup will be created. |
sourceBackupId |
String the source backup id. |
destinationBackupId |
String the id of the backup which will be created. It must conform to the regular expression a-z*[a-z0-9] and be between 2 and 60 characters in length. |
expireTime |
com.google.cloud.Timestamp the time that the new backup will automatically expire. |
Returns | |
---|---|
Type | Description |
OperationFuture<Backup,CopyBackupMetadata> |
createBackup(Backup backup)
public abstract OperationFuture<Backup,CreateBackupMetadata> createBackup(Backup backup)
Creates a new backup from a database in a Cloud Spanner. Any configuration options in the Backup instance will be included in the com.google.spanner.admin.database.v1.CreateBackupRequest.
Example to create an encrypted backup.
BackupId backupId = BackupId.of("project", "instance", "backup-id");
DatabaseId databaseId = DatabaseId.of("project", "instance", "database-id");
Timestamp expireTime = Timestamp.ofTimeMicroseconds(expireTimeMicros);
Timestamp versionTime = Timestamp.ofTimeMicroseconds(versionTimeMicros);
EncryptionConfig encryptionConfig =
EncryptionConfig.ofKey(
"projects/my-project/locations/some-location/keyRings/my-keyring/cryptoKeys/my-key"));
Backup backupToCreate = dbAdminClient
.newBackupBuilder(backupId)
.setDatabase(databaseId)
.setExpireTime(expireTime)
.setVersionTime(versionTime)
.setEncryptionConfig(encryptionConfig)
.build();
OperationFuture<Backup, CreateBackupMetadata> op = dbAdminClient.createBackup(backupToCreate);
Backup createdBackup = op.get();
Parameter | |
---|---|
Name | Description |
backup |
Backup the backup to be created |
Returns | |
---|---|
Type | Description |
OperationFuture<Backup,CreateBackupMetadata> |
Exceptions | |
---|---|
Type | Description |
SpannerException |
createBackup(String sourceInstanceId, String backupId, String databaseId, Timestamp expireTime)
public abstract OperationFuture<Backup,CreateBackupMetadata> createBackup(String sourceInstanceId, String backupId, String databaseId, Timestamp expireTime)
Creates a new backup from a database in a Cloud Spanner instance.
Example to create a backup.
String instance = my_instance_id;
String backupId = my_backup_id;
String databaseId = my_database_id;
Timestamp expireTime = Timestamp.ofTimeMicroseconds(micros);
OperationFuture<Backup, CreateBackupMetadata> op = dbAdminClient
.createBackup(
instanceId,
backupId,
databaseId,
expireTime);
Backup backup = op.get();
Parameters | |
---|---|
Name | Description |
sourceInstanceId |
String the id of the instance where the database to backup is located and where the backup will be created. |
backupId |
String the id of the backup which will be created. It must conform to the regular expression a-z*[a-z0-9] and be between 2 and 60 characters in length. |
databaseId |
String the id of the database to backup. |
expireTime |
com.google.cloud.Timestamp the time that the backup will automatically expire. |
Returns | |
---|---|
Type | Description |
OperationFuture<Backup,CreateBackupMetadata> |
Exceptions | |
---|---|
Type | Description |
SpannerException |
createDatabase(Database database, Iterable<String> statements)
public abstract OperationFuture<Database,CreateDatabaseMetadata> createDatabase(Database database, Iterable<String> statements)
Creates a database in a Cloud Spanner instance. Any configuration options in the Database instance will be included in the CreateDatabaseRequest.
Example to create an encrypted database.
Database dbInfo =
dbClient
.newDatabaseBuilder(DatabaseId.of("my-project", "my-instance", "my-database"))
.setEncryptionConfig(
EncryptionConfig.ofKey(
"projects/my-project/locations/some-location/keyRings/my-keyring/cryptoKeys/my-key"))
.build();
Operation<Database, CreateDatabaseMetadata> op = dbAdminClient
.createDatabase(
dbInfo,
Arrays.asList(
"CREATE TABLE Singers (
"
+ " SingerId INT64 NOT NULL,
"
+ " FirstName STRING(1024),
"
+ " LastName STRING(1024),
"
+ " SingerInfo BYTES(MAX)
"
+ ") PRIMARY KEY (SingerId)",
"CREATE TABLE Albums (
"
+ " SingerId INT64 NOT NULL,
"
+ " AlbumId INT64 NOT NULL,
"
+ " AlbumTitle STRING(MAX)