Search in sources :

Example 1 with RestoreInfo

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);
    }
}
Also used : RestoreInfo(com.google.cloud.spanner.RestoreInfo) Backup(com.google.cloud.spanner.Backup) Database(com.google.cloud.spanner.Database) RestoreDatabaseMetadata(com.google.spanner.admin.database.v1.RestoreDatabaseMetadata) ExecutionException(java.util.concurrent.ExecutionException) Timestamp(com.google.cloud.Timestamp)

Aggregations

Timestamp (com.google.cloud.Timestamp)1 Backup (com.google.cloud.spanner.Backup)1 Database (com.google.cloud.spanner.Database)1 RestoreInfo (com.google.cloud.spanner.RestoreInfo)1 RestoreDatabaseMetadata (com.google.spanner.admin.database.v1.RestoreDatabaseMetadata)1 ExecutionException (java.util.concurrent.ExecutionException)1