use of com.google.cloud.spanner.RestoreInfo in project java-spanner by googleapis.
the class SpannerSample method restoreBackup.
// [END spanner_list_backups]
// [START spanner_restore_backup]
static void restoreBackup(DatabaseAdminClient dbAdminClient, BackupId backupId, DatabaseId sourceDatabaseId, DatabaseId restoreToDatabase) {
Backup backup = dbAdminClient.newBackupBuilder(backupId).build();
// Initiate the request which returns an OperationFuture.
System.out.println(String.format("Restoring backup [%s] to database [%s]...", backup.getId().toString(), restoreToDatabase.toString()));
try {
OperationFuture<Database, RestoreDatabaseMetadata> op = backup.restore(restoreToDatabase);
// Wait until the database has been restored.
Database db = op.get();
// Refresh database metadata and get the restore info.
RestoreInfo restore = db.reload().getRestoreInfo();
Timestamp versionTime = Timestamp.fromProto(restore.getProto().getBackupInfo().getVersionTime());
System.out.println("Restored database [" + restore.getSourceDatabase().getName() + "] from [" + restore.getBackup().getName() + "] with version time [" + versionTime + "]");
} catch (ExecutionException e) {
throw SpannerExceptionFactory.newSpannerException(e.getCause());
} catch (InterruptedException e) {
throw SpannerExceptionFactory.propagateInterrupt(e);
}
}
Aggregations