Export asset metadata to Cloud Storage (original) (raw)

This document shows you how to export the asset metadata of your organization, folder, or project to a Cloud Storage bucket.

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

Provide the following values:

See the gcloud CLI reference for all options.

Example

Run the following command to export your resource metadata as it was on January 30, 2024 in the my-project project, to the file my-file.txt in the Cloud Storage bucket my-bucket.

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"

Example response

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 method and URL:

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

Headers:

X-Goog-User-Project: BILLING_PROJECT_ID

Request JSON body:

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

Provide the following values:

See the REST reference for all options.

Command examples

Run one of the following commands to export your resource metadata as it was on January 30, 2024 in the my-project project, to the file my-file.txt in the Cloud Storage bucket my-bucket.

curl (Linux, macOS, or 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

Example response

{ "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#

To learn how to install and use the client library for Cloud Asset Inventory, seeCloud Asset Inventory client libraries.

To authenticate to Cloud Asset Inventory, set up Application Default Credentials. For more information, seeSet up authentication for a local development environment.

Go

To learn how to install and use the client library for Cloud Asset Inventory, seeCloud Asset Inventory client libraries.

To authenticate to Cloud Asset Inventory, set up Application Default Credentials. For more information, seeSet up authentication for a local development environment.

Java

To learn how to install and use the client library for Cloud Asset Inventory, seeCloud Asset Inventory client libraries.

To authenticate to Cloud Asset Inventory, set up Application Default Credentials. For more information, seeSet up authentication for a local development environment.

Node.js

To learn how to install and use the client library for Cloud Asset Inventory, seeCloud Asset Inventory client libraries.

To authenticate to Cloud Asset Inventory, set up Application Default Credentials. For more information, seeSet up authentication for a local development environment.

PHP

To learn how to install and use the client library for Cloud Asset Inventory, seeCloud Asset Inventory client libraries.

To authenticate to Cloud Asset Inventory, set up Application Default Credentials. For more information, seeSet up authentication for a local development environment.

Python

To learn how to install and use the client library for Cloud Asset Inventory, seeCloud Asset Inventory client libraries.

To authenticate to Cloud Asset Inventory, set up Application Default Credentials. For more information, seeSet up authentication for a local development environment.

Ruby

To learn how to install and use the client library for Cloud Asset Inventory, seeCloud Asset Inventory client libraries.

To authenticate to Cloud Asset Inventory, set up Application Default Credentials. For more information, seeSet up authentication for a local development environment.

Exports take time to complete. To check if an export is done, you can query the operation using its operation ID.

Be aware that even if your export is done, someone might have made another export request to the same destination as a different operation. New export requests to the same destination can be made after a previous request has finished, or if more than 15 minutes has elapsed. Export requests made outside of these conditions are rejected by Cloud Asset Inventory.