创建备份

此代码段会创建一个新备份并为其分配特定 ID。该代码会同步等待长时间运行的备份创建操作完成,然后返回响应。

代码示例

Java

如需向 AlloyDB 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅 为本地开发环境设置身份验证。

import com.google.cloud.alloydb.v1beta.AlloyDBAdminClient;
import com.google.cloud.alloydb.v1beta.Backup;
import com.google.cloud.alloydb.v1beta.LocationName;

public class SyncCreateBackupStringBackupString {

  public static void main(String[] args) throws Exception {
    syncCreateBackupStringBackupString();
  }

  public static void syncCreateBackupStringBackupString() throws Exception {
    // This snippet has been automatically generated and should be regarded as a code template only.
    // It will require modifications to work:
    // - It may require correct/in-range values for request initialization.
    // - It may require specifying regional endpoints when creating the service client as shown in
    // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    try (AlloyDBAdminClient alloyDBAdminClient = AlloyDBAdminClient.create()) {
      String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString();
      Backup backup = Backup.newBuilder().build();
      String backupId = "backupId2121930365";
      Backup response = alloyDBAdminClient.createBackupAsync(parent, backup, backupId).get();
    }
  }
}

后续步骤

如需搜索和过滤其他 Google Cloud 产品的代码示例,请参阅Google Cloud 示例浏览器。