将资产元数据导出到 Cloud Storage

本文档介绍如何将项目的资产元数据导出到 Cloud Storage 存储桶

准备工作

  1. 在您运行 Cloud Asset Inventory 命令的项目中启用 Cloud Asset Inventory API。

    启用 Cloud Asset Inventory API

  2. 确保您的账号拥有调用 Cloud Asset Inventory API 的正确角色。如需了解每种通话类型的各项权限,请参阅权限

  3. 创建 Cloud Storage 存储桶以导出到该存储分区(如果您还没有存储分区)。

限制

  • 不支持使用自定义 Cloud Key Management Service (Cloud KMS) 密钥加密的 Cloud Storage 存储分区。

  • Cloud Storage 存储桶不得设置保留政策

  • 在导出过程中,该操作可能会在输出文件夹中创建临时文件。操作正在进行时,请勿移除这些临时文件。 操作完成后,系统会自动移除临时文件。

  • ACCESS_POLICY 内容类型只能在组织级层导出。

  • 如果您要导出到的文件已存在且正在导出,系统会返回 400 错误。

  • 为了测试权限,Cloud Asset Inventory 会在导出数据之前创建一个空文件,这会额外发送一个 google.cloud.storage.object.v1.finalized Cloud Storage 触发事件。

将资源快照导出到 Cloud Storage

gcloud

gcloud asset export \
    --SCOPE \
    --billing-project=BILLING_PROJECT_ID \
    --asset-types=ASSET_TYPE_1,ASSET_TYPE_2,... \
    --content-type=CONTENT_TYPE \
    --relationship-types=RELATIONSHIP_TYPE_1,RELATIONSHIP_TYPE_2,... \
    --snapshot-time="SNAPSHOT_TIME" \
    --OUTPUT_TYPE

请提供以下值:

  • SCOPE:请使用以下某个值:

    • project=PROJECT_ID,其中 PROJECT_ID 是包含要导出的资源元数据的项目的 ID。
    • folder=FOLDER_ID,其中 FOLDER_ID 是包含要导出的资源元数据的文件夹的 ID。

      如何查找 Google Cloud 文件夹的 ID

      Google Cloud 控制台

      如需查找 Google Cloud 文件夹的 ID,请完成以下步骤:

      1. 前往 Google Cloud 控制台。

        前往 Google Cloud 控制台

      2. 点击菜单栏中的切换器列表框。
      3. 从列表框中选择您的组织。
      4. 搜索您的文件夹名称。文件夹 ID 会显示在文件夹名称旁边。

      gcloud CLI

      您可以使用以下命令检索组织级层文件夹的 ID: Google Cloud

      gcloud resource-manager folders list \
          --organization=$(gcloud organizations describe ORGANIZATION_NAME \
            --format="value(name.segment(1))") \
          --filter='"DISPLAY_NAME":"TOP_LEVEL_FOLDER_NAME"' \
          --format="value(ID)"

      其中,TOP_LEVEL_FOLDER_NAME 是文件夹名称的部分或完整字符串匹配项。移除 --format 标志即可查看有关已找到文件夹的更多信息。

      上一个命令不会返回文件夹中子文件夹的 ID。为此,请使用顶级文件夹的 ID 运行以下命令:

      gcloud resource-manager folders list --folder=FOLDER_ID
    • organization=ORGANIZATION_ID,其中 ORGANIZATION_ID 是包含您要导出的资产元数据的组织的 ID。

      如何查找 Google Cloud 组织的 ID

      Google Cloud 控制台

      如需查找 Google Cloud 组织的 ID,请完成以下步骤:

      1. 前往 Google Cloud 控制台。

        前往 Google Cloud 控制台

      2. 点击菜单栏中的切换器列表框。
      3. 从列表框中选择您的组织。
      4. 点击全部标签页。组织 ID 显示在组织名称旁边。

      gcloud CLI

      您可以使用以下命令检索 Google Cloud 组织的 ID:

      gcloud organizations describe ORGANIZATION_NAME --format="value(name.segment(1))"
  • BILLING_PROJECT_ID:可选。默认 Cloud Asset Inventory 服务代理所在的项目的 ID,该项目具有管理您的 BigQuery 数据集和表的权限。 详细了解如何设置结算项目

  • ASSET_TYPE_#:可选。以英文逗号分隔的 可搜索资产类型列表。 支持 RE2 兼容的正则表达式。如果正则表达式与任何支持的资源类型均不匹配,则会返回 INVALID_ARGUMENT 错误。如果未指定 --asset-types,则返回所有资产类型。
  • CONTENT_TYPE:可选。您要检索的元数据的 内容类型。如果未指定 --content-type,则仅返回基本信息,例如资产名称、资产上次更新时间以及资产所属的项目、文件夹和组织。
  • RELATIONSHIP_TYPE_#:可选。需要有权访问 Security Command Center 高级层级或 Enterprise 层级,或者 Gemini Cloud Assist。以英文逗号分隔的要检索的资产关系类型列表。您必须将 CONTENT_TYPE 设置为 RELATIONSHIP, 才能使此功能正常运行。
  • SNAPSHOT_TIME:可选。您希望截取资源快照的时间,采用 gcloud topic datetime 格式。该值必须是过去不超过 35 天的时间。如果未指定 --snapshot-time,则在当前时间截取快照。
  • OUTPUT_TYPE:请使用以下某个值:

    • --output-path="gs://BUCKET_NAME/FILE_NAME" 将输出写入文件,其中:

      • BUCKET_NAME 是要写入的 Cloud Storage 存储桶的名称。
      • FILE_NAME 是要写入 Cloud Storage 存储桶中的文件。
    • --output-path-prefix="gs://BUCKET_NAME/FOLDER_NAME",用于将输出写入文件夹,其中:

      • BUCKET_NAME 是要写入的 Cloud Storage 存储桶的名称。
      • FOLDER_NAME 是 Cloud Storage 存储桶中要写入的文件夹。输出会拆分为以资源类型命名的子文件夹。子文件夹不得已存在于您指定的文件夹中。

如需了解所有选项,请参阅 gcloud CLI 参考文档

示例

运行以下命令,将 my-project 项目中 2024 年 1 月 30 日的 resource 元数据导出到 Cloud Storage 存储桶 my-bucket 中的文件 my-file.txt

gcloud asset export \
    --project=my-project \
    --billing-project=my-project \
    --content-type=resource \
    --snapshot-time="2024-01-30" \
    --output-path="gs://my-bucket/my-file.txt"

示例响应

Export in progress for root asset [projects/my-project].
Use [gcloud asset operations describe projects/000000000000/operations/ExportAssets/RESOURCE/00000000000000000000000000000000] to check the status of the operation.

REST

HTTP 方法和网址:

POST https://cloudasset.googleapis.com/v1/SCOPE_PATH:exportAssets

标头:

X-Goog-User-Project: BILLING_PROJECT_ID

请求 JSON 正文:

{
  "assetTypes": [
    "ASSET_TYPE_1",
    "ASSET_TYPE_2",
    "..."
  ],
  "contentType": "CONTENT_TYPE",
  "relationshipTypes": [
    "RELATIONSHIP_TYPE_1",
    "RELATIONSHIP_TYPE_2",
    "..."
  ],
  "readTime": "SNAPSHOT_TIME",
  "outputConfig": {
    "gcsDestination": {
      OUTPUT_TYPE
    }
  }
}

请提供以下值:

  • SCOPE_PATH:请使用以下某个值:

    允许使用的值包括:

    • projects/PROJECT_ID,其中 PROJECT_ID 是包含要导出的资源元数据的项目的 ID。
    • projects/PROJECT_NUMBER,其中 PROJECT_NUMBER 是包含要导出的资源元数据的项目的编号。

      如何查找 Google Cloud 项目编号

      Google Cloud 控制台

      如需查找 Google Cloud 项目编号,请完成以下步骤:

      1. 前往 Google Cloud 控制台中的欢迎页面。

        前往“欢迎”页面

      2. 点击菜单栏中的切换器列表框。
      3. 从列表框中选择您的组织,然后搜索您的项目名称。 项目名称、项目编号和项目 ID 显示在欢迎标题附近。

        最多可显示 4,000 个资源。如果您没有看到要查找的项目,请前往管理资源页面,然后使用该项目的名称过滤列表。

      gcloud CLI

      您可以使用以下命令检索 Google Cloud 项目编号:

      gcloud projects describe PROJECT_ID --format="value(projectNumber)"
    • folders/FOLDER_ID,其中 FOLDER_ID 是包含要导出的资源元数据的文件夹的 ID。

      如何查找 Google Cloud 文件夹的 ID

      Google Cloud 控制台

      如需查找 Google Cloud 文件夹的 ID,请完成以下步骤:

      1. 前往 Google Cloud 控制台。

        前往 Google Cloud 控制台

      2. 点击菜单栏中的切换器列表框。
      3. 从列表框中选择您的组织。
      4. 搜索您的文件夹名称。文件夹 ID 会显示在文件夹名称旁边。

      gcloud CLI

      您可以使用以下命令检索组织级层文件夹的 ID: Google Cloud

      gcloud resource-manager folders list \
          --organization=$(gcloud organizations describe ORGANIZATION_NAME \
            --format="value(name.segment(1))") \
          --filter='"DISPLAY_NAME":"TOP_LEVEL_FOLDER_NAME"' \
          --format="value(ID)"

      其中,TOP_LEVEL_FOLDER_NAME 是文件夹名称的部分或完整字符串匹配项。移除 --format 标志即可查看有关已找到文件夹的更多信息。

      上一个命令不会返回文件夹中子文件夹的 ID。为此,请使用顶级文件夹的 ID 运行以下命令:

      gcloud resource-manager folders list --folder=FOLDER_ID
    • organizations/ORGANIZATION_ID,其中 ORGANIZATION_ID 是包含您要导出的资产元数据的组织的 ID。

      如何查找 Google Cloud 组织的 ID

      Google Cloud 控制台

      如需查找 Google Cloud 组织的 ID,请完成以下步骤:

      1. 前往 Google Cloud 控制台。

        前往 Google Cloud 控制台

      2. 点击菜单栏中的切换器列表框。
      3. 从列表框中选择您的组织。
      4. 点击全部标签页。组织 ID 显示在组织名称旁边。

      gcloud CLI

      您可以使用以下命令检索 Google Cloud 组织的 ID:

      gcloud organizations describe ORGANIZATION_NAME --format="value(name.segment(1))"
  • BILLING_PROJECT_ID:默认 Cloud Asset Inventory 服务代理所在的项目的 ID,该项目具有管理 BigQuery 数据集和表的权限。 详细了解如何设置结算项目

  • ASSET_TYPE_#:可选。 可搜索的资产类型数组。 支持 RE2 兼容的正则表达式。如果正则表达式与任何支持的资源类型均不匹配,则会返回 INVALID_ARGUMENT 错误。如果未指定 assetTypes,则返回所有资产类型。
  • CONTENT_TYPE:可选。您要检索的元数据的 内容类型。如果未指定 contentType,则仅返回基本信息,例如资产名称、资产上次更新时间以及资产所属的项目、文件夹和组织。
  • RELATIONSHIP_TYPE_#:可选。需要有权访问 Security Command Center 高级层级或 Enterprise 层级,或者 Gemini Cloud Assist。以英文逗号分隔的要检索的资产关系类型列表。您必须将 CONTENT_TYPE 设置为 RELATIONSHIP, 才能使此功能正常运行。
  • SNAPSHOT_TIME:可选。您希望截取资源快照的时间,采用 RFC 3339 格式。该值必须是过去不超过 35 天的时间。如果未指定 readTime,则在当前时间截取快照。
  • OUTPUT_TYPE:请使用以下某个值:

    • "uri": "gs://BUCKET_NAME/FILE_NAME" 将输出写入文件,其中:

      • BUCKET_NAME 是要写入的 Cloud Storage 存储桶的名称。
      • FILE_NAME 是要写入 Cloud Storage 存储桶中的文件。
    • "uriPrefix": "gs://BUCKET_NAME/FOLDER_NAME",用于将输出写入文件夹,其中:

      • BUCKET_NAME 是要写入的 Cloud Storage 存储桶的名称。
      • FOLDER_NAME 是 Cloud Storage 存储桶中要写入的文件夹。输出会拆分为以资源类型命名的子文件夹。子文件夹不得已存在于您指定的文件夹中。

如需了解所有选项,请参阅 REST 参考文档

命令示例

运行以下任一命令,将 my-project 项目中 2024 年 1 月 30 日的 resource 元数据导出到 Cloud Storage 存储桶 my-bucket 中的文件 my-file.txt

curl(Linux、macOS 或 Cloud Shell)

curl -X POST \
     -H "X-Goog-User-Project: BILLING_PROJECT_ID" \
     -H "Authorization: Bearer $(gcloud auth print-access-token)" \
     -H "Content-Type: application/json; charset=utf-8" \
     -d '{
            "contentType": "RESOURCE",
            "readTime": "2024-01-30T00:00:00Z",
            "outputConfig": {
              "gcsDestination": {
                "uri": "gs://my-bucket/my-file"
              }
            }
          }' \
     https://cloudasset.googleapis.com/v1/projects/my-project:exportAssets

PowerShell (Windows)

$cred = gcloud auth print-access-token

$headers = @{ 
  "X-Goog-User-Project" = "BILLING_PROJECT_ID";
  "Authorization" = "Bearer $cred"
}


$body = @"
{
  "contentType": "RESOURCE",
  "readTime": "2024-01-30T00:00:00Z",
  "outputConfig": {
    "gcsDestination": {
      "uri": "gs://my-bucket/my-file"
    }
  }
}
"@

Invoke-WebRequest `
  -Method POST `
  -Headers $headers `
  -ContentType: "application/json; charset=utf-8" `
  -Body $body `
  -Uri "https://cloudasset.googleapis.com/v1/projects/my-project:exportAssets" | Select-Object -Expand Content

示例响应

{
  "name": "projects/000000000000/operations/ExportAssets/RESOURCE/00000000000000000000000000000000",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.asset.v1.ExportAssetsRequest",
    "parent": "projects/000000000000",
    "readTime": "2024-01-30T00:00:00Z",
    "contentType": "RESOURCE",
    "outputConfig": {
      "gcsDestination": {
        "uri": "gs://my-bucket/export.txt"
      }
    }
  }
}

C#

如需了解如何安装和使用 Cloud Asset Inventory 客户端库,请参阅 Cloud Asset Inventory 客户端库

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


using Google.Api.Gax.ResourceNames;
using Google.Cloud.Asset.V1;

public class ExportAssetsSample
{
    public ExportAssetsResponse ExportAssets(string bucketName, string projectId)
    {
        string assetDumpFile = $"gs://{bucketName}/my-assets.txt";
        // Create the client
        AssetServiceClient client = AssetServiceClient.Create();
        // Build the request
        ExportAssetsRequest request = new ExportAssetsRequest
        {
            ParentAsResourceName = ProjectName.FromProject(projectId),
            OutputConfig = new OutputConfig
            {
                GcsDestination = new GcsDestination { Uri = assetDumpFile }
            }
        };
        // Start the long-running export operation
        var operation = client.ExportAssets(request);
        // Wait for it to complete (or fail)
        operation = operation.PollUntilCompleted();
        // Return the result
        return operation.Result;
    }
}

Go

如需了解如何安装和使用 Cloud Asset Inventory 客户端库,请参阅 Cloud Asset Inventory 客户端库

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


// Sample asset-quickstart exports assets to given path.
package main

import (
	"context"
	"fmt"
	"log"
	"os"

	asset "cloud.google.com/go/asset/apiv1"
	"cloud.google.com/go/asset/apiv1/assetpb"
)

func main() {
	ctx := context.Background()
	projectID := os.Getenv("GOOGLE_CLOUD_PROJECT")
	client, err := asset.NewClient(ctx)
	if err != nil {
		log.Fatal(err)
	}
	defer client.Close()
	bucketName := fmt.Sprintf("%s-for-assets", projectID)
	assetDumpFile := fmt.Sprintf("gs://%s/my-assets.txt", bucketName)
	req := &assetpb.ExportAssetsRequest{
		Parent: fmt.Sprintf("projects/%s", projectID),
		OutputConfig: &assetpb.OutputConfig{
			Destination: &assetpb.OutputConfig_GcsDestination{
				GcsDestination: &assetpb.GcsDestination{
					ObjectUri: &assetpb.GcsDestination_Uri{
						Uri: string(assetDumpFile),
					},
				},
			},
		},
	}
	operation, err := client.ExportAssets(ctx, req)
	if err != nil {
		log.Fatal(err)
	}
	response, err := operation.Wait(ctx)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Print(response)
}

Java

如需了解如何安装和使用 Cloud Asset Inventory 客户端库,请参阅 Cloud Asset Inventory 客户端库

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

// Imports the Google Cloud client library

import com.google.cloud.ServiceOptions;
import com.google.cloud.asset.v1.AssetServiceClient;
import com.google.cloud.asset.v1.ContentType;
import com.google.cloud.asset.v1.ExportAssetsRequest;
import com.google.cloud.asset.v1.ExportAssetsRequest.Builder;
import com.google.cloud.asset.v1.ExportAssetsResponse;
import com.google.cloud.asset.v1.GcsDestination;
import com.google.cloud.asset.v1.OutputConfig;
import com.google.cloud.asset.v1.ProjectName;
import java.io.IOException;
import java.util.Arrays;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class ExportAssetsExample {

  // Use the default project Id.
  private static final String projectId = ServiceOptions.getDefaultProjectId();

  /**
   * Export assets for a project.
   *
   * @param exportPath where the results will be exported to
   * @param contentType determines the schema for the table
   * @param assetTypes a list of asset types to export. if empty, export all.
   */
  public static void exportAssets(String exportPath, ContentType contentType, String[] assetTypes)
      throws IOException,
          IllegalArgumentException,
          InterruptedException,
          ExecutionException,
          TimeoutException {
    try (AssetServiceClient client = AssetServiceClient.create()) {
      ProjectName parent = ProjectName.of(projectId);
      OutputConfig outputConfig =
          OutputConfig.newBuilder()
              .setGcsDestination(GcsDestination.newBuilder().setUri(exportPath).build())
              .build();
      Builder exportAssetsRequestBuilder =
          ExportAssetsRequest.newBuilder()
              .setParent(parent.toString())
              .setContentType(contentType)
              .setOutputConfig(outputConfig);
      if (assetTypes.length > 0) {
        exportAssetsRequestBuilder.addAllAssetTypes(Arrays.asList(assetTypes));
      }
      ExportAssetsRequest request = exportAssetsRequestBuilder.build();
      ExportAssetsResponse response = client.exportAssetsAsync(request).get(5, TimeUnit.MINUTES);
      System.out.println(response);
    }
  }
}

Node.js

如需了解如何安装和使用 Cloud Asset Inventory 客户端库,请参阅 Cloud Asset Inventory 客户端库

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

/**
 * TODO(developer): Uncomment these variables before running the sample.
 */
// const dumpFilePath = 'gs://my-bucket/my-assets.txt';
// const contentType = 'RESOURCE';

const {AssetServiceClient} = require('@google-cloud/asset');
const client = new AssetServiceClient();

async function exportAssets() {
  const projectId = await client.getProjectId();
  const projectResource = `projects/${projectId}`;

  // TODO(developer): choose the dump file path
  // const dumpFilePath = 'Dump file path, e.g.: gs://<my_bucket>/<my_asset_file>'
  const request = {
    parent: projectResource,
    contentType: contentType,
    outputConfig: {
      gcsDestination: {
        uri: dumpFilePath,
      },
    },
  };

  // Handle the operation using the promise pattern.
  const [operation] = await client.exportAssets(request);

  // Operation#promise starts polling for the completion of the operation.
  const [result] = await operation.promise();

  // Do things with with the response.
  console.log(result);
}
exportAssets().catch(err => {
  throw err;
});

PHP

如需了解如何安装和使用 Cloud Asset Inventory 客户端库,请参阅 Cloud Asset Inventory 客户端库

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

use Google\Cloud\Asset\V1\Client\AssetServiceClient;
use Google\Cloud\Asset\V1\ExportAssetsRequest;
use Google\Cloud\Asset\V1\GcsDestination;
use Google\Cloud\Asset\V1\OutputConfig;

/**
 * Export assets for given project to specified dump file path.
 *
 * @param string $projectId the project Id for export assets.
 * @param string $dumpFilePath the file path where the assets will be dumped to.
 *        e.g.: gs://[bucket-name]/[asset-file-name].
 */
function export_assets(string $projectId, string $dumpFilePath)
{
    $client = new AssetServiceClient();

    $gcsDestination = new GcsDestination(['uri' => $dumpFilePath]);
    $outputConfig = new OutputConfig(['gcs_destination' => $gcsDestination]);
    $request = (new ExportAssetsRequest())
        ->setParent("projects/$projectId")
        ->setOutputConfig($outputConfig);

    $resp = $client->exportAssets($request);

    $resp->pollUntilComplete();

    if ($resp->operationSucceeded()) {
        print('The result is dumped to $dumpFilePath successfully.' . PHP_EOL);
    } else {
        $error = $resp->getError();
        printf('There was an error: "%s".' . PHP_EOL, $error?->getMessage());
        // handleError($error)
    }
}

Python

如需了解如何安装和使用 Cloud Asset Inventory 客户端库,请参阅 Cloud Asset Inventory 客户端库

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

from google.cloud import asset_v1

# TODO project_id = 'Your Google Cloud Project ID'
# TODO dump_file_path = 'Your asset dump file path'

client = asset_v1.AssetServiceClient()
parent = f"projects/{project_id}"
output_config = asset_v1.OutputConfig()
output_config.gcs_destination.uri = dump_file_path
request_options = {"parent": parent, "output_config": output_config}

if content_type is not None:
    request_options["content_type"] = content_type

response = client.export_assets(request=request_options)
print(response.result())

Ruby

如需了解如何安装和使用 Cloud Asset Inventory 客户端库,请参阅 Cloud Asset Inventory 客户端库

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

require "google/cloud/asset"

asset_service = Google::Cloud::Asset.asset_service
# project_id = 'YOUR_PROJECT_ID'
formatted_parent = asset_service.project_path project: project_id
# Assets dump file path, e.g.: gs://[YOUR_BUCKET]/[YOUR_ASSETS_FILE]
# dump_file_path = 'YOUR_ASSET_DUMP_FILE_PATH'
output_config = {
  gcs_destination: {
    uri: dump_file_path
  }
}

operation = asset_service.export_assets(
  parent: formatted_parent, output_config: output_config
) do |op|
  # Handle the error.
  raise op.results.message if op.error?
end

operation.wait_until_done!
response = operation.response
puts "Exported assets to: #{response.output_config.gcs_destination.uri}"
# Do things with the result

查看导出状态

导出需要一段时间才能完成。如需检查导出是否完成,您可以使用相应操作的操作 ID 查询该操作。

请注意,即使您的导出操作已完成,也可能有人以不同的操作向同一目标位置发出了另一项导出请求。只有在之前的导出请求完成后,或者在超过 15 分钟后,才能向同一目标发出新的导出请求。如果导出请求不符合上述条件,Cloud Asset Inventory 会拒绝该请求。

gcloud

如需查看导出状态,请按照以下说明操作:

  1. 从导出请求的响应中获取 OPERATION_PATH,其中包括操作 ID。OPERATION_PATH 显示在导出响应中,格式如下:

    projects/PROJECT_NUMBER/operations/ExportAssets/CONTENT_TYPE/OPERATION_ID
    
  2. 要检查导出状态,请使用 OPERATION_PATH 运行以下命令:

    gcloud asset operations describe OPERATION_PATH
    

REST

如需查看导出状态,请按照以下说明操作:

  1. 从导出请求的响应中获取 OPERATION_PATH,其中包括操作 ID。OPERATION_PATH 显示为导出响应中 name 字段的值,其格式如下所示:

    projects/PROJECT_NUMBER/operations/ExportAssets/CONTENT_TYPE/OPERATION_ID
    
  2. 如需检查导出状态,请发出以下请求。

    REST

    HTTP 方法和网址:

    GET https://cloudasset.googleapis.com/v1/OPERATION_PATH
    

    命令示例

    curl(Linux、macOS 或 Cloud Shell)

    curl -X GET \
         -H "Authorization: Bearer $(gcloud auth print-access-token)" \
         https://cloudasset.googleapis.com/v1/OPERATION_PATH

    PowerShell (Windows)

    $cred = gcloud auth print-access-token
    
    $headers = @{ 
      "Authorization" = "Bearer $cred"
    }
    
    
    Invoke-WebRequest `
      -Method GET `
      -Headers $headers `
      -Uri "https://cloudasset.googleapis.com/v1/OPERATION_PATH" | Select-Object -Expand Content

    示例响应

    {
      "name": "projects/000000000000/operations/ExportAssets/RESOURCE/00000000000000000000000000000000",
      "metadata": {
        "@type": "type.googleapis.com/google.cloud.asset.v1.ExportAssetsRequest",
        "parent": "projects/000000000000",
        "readTime": "2024-01-30T00:00:00Z",
        "contentType": "RESOURCE",
        "outputConfig": {
          "gcsDestination": {
            "uri": "gs://my-bucket/export.txt"
          }
        }
      }
    }

查看资产快照

要查看资产快照,请执行以下操作:

  1. 前往 Google Cloud 控制台中的 Cloud Storage 存储桶页面。

    进入“存储桶”

  2. 点击您将资产快照导出到的存储桶的名称,然后点击导出文件名。

  3. 点击下载下载资产快照,然后在所选的文本编辑器中打开该快照。