本頁說明如何建立、查看、列出、取消及刪除 儲存空間批次作業工作。並說明如何將 Cloud 稽核記錄與儲存空間批次作業工作搭配使用。
事前準備
如要建立及管理儲存空間批次作業工作,請完成下列各節的步驟。
設定 Storage Intelligence
如要建立及管理儲存空間批次作業工作,請在要執行工作的值區上設定 Storage Intelligence。
設定 Google Cloud CLI
您必須使用 Google Cloud CLI 516.0.0 以上版本。
設定預設專案
設定要建立儲存空間批次作業工作所在的專案。
gcloud config set project PROJECT_ID
其中 PROJECT_ID 是專案 ID。
啟用 API
啟用 Storage 批次作業 API。
gcloud services enable storagebatchoperations.googleapis.com
建立資訊清單
如要使用資訊清單進行物件選取,請建立資訊清單。
建立儲存空間批次作業工作
本節說明如何建立儲存空間批次作業工作。
指令列
-
In the Google Cloud console, activate Cloud Shell.
At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.
在開發環境中執行
gcloud storage batch-operations jobs create
指令。gcloud storage batch-operations jobs create JOB_NAME --bucket=BUCKET_NAME OBJECT_SELECTION_FLAG JOB_TYPE_FLAG
其中:
JOB_NAME
是儲存空間批次作業工作的名稱。BUCKET_NAME
是值區名稱,其中包含一或多個要處理的物件。OBJECT_SELECTION_FLAG
是下列其中一個標記:JOB_TYPE_FLAG
是下列其中一個標記,視工作類型而定。--delete-object
:刪除一或多個物件。--put-metadata
:更新物件中繼資料。物件中繼資料會以「鍵-值」組合形式儲存。為要修改的中繼資料指定鍵/值組合。您可以將一或多個 鍵/值組合指定為清單。--rewrite-object
:更新一或多個物件的客戶代管加密金鑰。--put-object-event-based-hold
:啟用事件為基礎的物件保留。--no-put-object-event-based-hold
:停用事件型 物件保留。--put-object-temporary-hold
:啟用暫時物件保留功能。--no-put-object-temporary-hold
:停用臨時物件保留功能。
REST API
JSON API
建立 JSON 檔案,其中包含 儲存空間批次作業工作的設定。以下是常見的設定:
{ "Description": "JOB_DESCRIPTION", "BucketList": { "Buckets": [ { "Bucket": "BUCKET_NAME", "Manifest": { "manifest_location": "MANIFEST_LOCATION" } "PrefixList": { "include_object_prefixes": "OBJECT_PREFIXES" } } ] }, "DeleteObject": { "permanent_object_deletion_enabled": OBJECT_DELETION_VALUE } "RewriteObject": { "kms_key":"KMS_KEY_VALUE" } "PutMetadata": { METADATA_KEY= METADATA_VALUE, ..., } "PutObjectHold": { "temporary_hold": TEMPORARY_HOLD_VALUE, "event_based_hold": EVENT_BASED_HOLD_VALUE } }
其中:
JOB_NAME
是儲存空間批次作業工作的名稱。JOB_DESCRIPTION
是儲存空間批次作業工作的說明。BUCKET_NAME
是值區名稱,其中包含一或多個要處理的物件。如要指定要處理的物件,請在 JSON 檔案中使用下列任一屬性:
視要處理的工作而定,指定下列任一選項:
刪除物件:
"DeleteObject": { "permanent_object_deletion_enabled": OBJECT_DELETION_VALUE }
其中
OBJECT_DELETION_VALUE
是用來刪除物件的TRUE
。更新物件的客戶管理的加密金鑰:
"RewriteObject": { "kms_key": KMS_KEY_VALUE }
其中
KMS_KEY_VALUE
是您要更新的物件 KMS 金鑰值。更新物件中繼資料:
"PutMetadata": { METADATA_KEY= METADATA_VALUE, ..., }
其中
METADATA_VALUE
是物件中繼資料的鍵值。您可以將一或多個 鍵/值組合指定為清單。更新物件保留:
"PutObjectHold": { "temporary_hold": TEMPORARY_HOLD_VALUE, "event_based_hold": EVENT_BASED_HOLD_VALUE }
其中:
TEMPORARY_HOLD_VALUE
可用於啟用或停用暫時物件保留功能。值為1
時會啟用保留,值為2
時會停用保留。EVENT_BASED_HOLD_VALUE
可用於啟用或停用事件型物件保留。值為1
時會啟用保留,值為2
時會停用保留。
使用
cURL
來透過POST
儲存空間批次作業工作要求呼叫 JSON API:curl -X POST --data-binary @JSON_FILE_NAME \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json" \ "https://storagebatchoperations.googleapis.com/v1/project=PROJECT_ID/locations/global/jobs?job_id=JOB_ID"
其中:
JSON_FILE_NAME
是 JSON 檔案的名稱。PROJECT_ID
是專案的 ID 或編號。例如:my-project
。JOB_ID
是儲存空間批次作業工作的名稱。
取得儲存空間批次作業工作詳細資料
本節說明如何取得儲存空間批次作業工作詳細資料。
指令列
-
In the Google Cloud console, activate Cloud Shell.
At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.
在開發環境中執行
gcloud storage batch-operations jobs describe
指令。gcloud storage batch-operations jobs describe JOB_ID
其中:
JOB_ID
是儲存空間批次作業工作的名稱。
REST API
JSON API
使用
cURL
透過GET
儲存空間批次作業工作要求呼叫 JSON API:curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://storagebatchoperations.googleapis.com/v1/projects/PROJECT_ID/locations/global/jobs?JOB_ID"
其中:
PROJECT_ID
是專案的 ID 或編號。例如:my-project
。JOB_ID
是儲存空間批次作業工作的名稱。
列出儲存空間批次作業工作
本節說明如何列出專案中的儲存空間批次作業工作。
指令列
-
In the Google Cloud console, activate Cloud Shell.
At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.
在開發環境中執行
gcloud storage batch-operations jobs list
指令。gcloud storage batch-operations jobs list
REST API
JSON API
使用
cURL
透過LIST
儲存空間批次作業工作要求呼叫 JSON API:curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://storagebatchoperations.googleapis.com/v1/projects/PROJECT_ID/locations/global/jobs"
其中:
PROJECT_ID
是專案的 ID 或編號。例如:my-project
。
取消 Storage 批次作業工作
本節說明如何取消專案中的儲存空間批次作業工作。
指令列
-
In the Google Cloud console, activate Cloud Shell.
At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.
在開發環境中執行
gcloud storage batch-operations jobs cancel
指令。gcloud storage batch-operations jobs cancel JOB_ID
其中:
JOB_ID
是儲存空間批次作業工作的名稱。
REST API
JSON API
使用
cURL
透過CANCEL
儲存空間批次作業工作要求呼叫 JSON API:curl -X CANCEL \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://storagebatchoperations.googleapis.com/v1/projects/PROJECT_ID/locations/global/jobs/JOB_ID"
其中:
PROJECT_ID
是專案的 ID 或編號。例如:my-project
。JOB_ID
是儲存空間批次作業工作的名稱。
刪除儲存空間批次作業工作
本節說明如何刪除儲存空間批次作業工作。
指令列
-
In the Google Cloud console, activate Cloud Shell.
At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.
在開發環境中執行
gcloud storage batch-operations jobs delete
指令。gcloud storage batch-operations jobs delete JOB_ID
其中:
JOB_ID
是儲存空間批次作業工作的名稱。
REST API
JSON API
使用
cURL
透過DELETE
儲存空間批次作業工作要求呼叫 JSON API:curl -X DELETE \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://storagebatchoperations.googleapis.com/v1/projects/PROJECT_ID/locations/global/jobs/JOB_ID"
其中:
PROJECT_ID
是專案的 ID 或編號。例如:my-project
。JOB_ID
是儲存空間批次作業工作的名稱。
使用儲存空間分析資料集建立儲存空間批次作業工作
如要使用 Storage 深入分析資料集建立儲存空間批次作業工作,請完成下列各節中的步驟。
使用儲存空間分析資料集建立資訊清單
您可以從 BigQuery 擷取資料,為儲存空間批次作業工作建立資訊清單。如要這樣做,您需要查詢已連結的資料集,將結果資料匯出為 CSV 檔案,然後儲存至 Cloud Storage 值區。儲存空間批次作業工作就能使用這個 CSV 檔案做為資訊清單。
在 BigQuery 中針對儲存空間分析資料集檢視畫面執行下列 SQL 查詢,即可擷取名為 Temp_Training
且大小超過 1 KiB 的物件:
EXPORT DATA OPTIONS( uri=`URI`, format=`CSV`, overwrite=OVERWRITE_VALUE, field_delimiter=',') AS SELECT bucket, name, generation FROM DATASET_VIEW_NAME WHERE bucket = BUCKET_NAME AND name LIKE (`Temp_Training%`) AND size > 1024 * 1024 AND snapshotTime = SNAPSHOT_TIME
其中:
URI
是包含資訊清單的值區 URI。例如,gs://bucket_name/path_to_csv_file/*.csv
。使用*.csv
萬用字元時,BigQuery 會將結果匯出至多個 CSV 檔案。OVERWRITE_VALUE
是布林值。如果設為true
,匯出作業會覆寫指定位置的現有檔案。DATASET_VIEW_NAME
是儲存空間分析資料集檢視畫面的完整名稱,格式為PROJECT_ID.DATASET_ID.VIEW_NAME
。如要查看資料集名稱,請查看已連結的資料集。其中:
PROJECT_ID
是專案的 ID 或編號。例如:my-project
。DATASET_ID
是資料集名稱。例如:objects-deletion-dataset
。VIEW_NAME
是資料集檢視畫面的名稱。例如:bucket_attributes_view
。
BUCKET_NAME
是值區名稱。例如:my-bucket
。SNAPSHOT_TIME
是儲存空間分析資料集檢視畫面的快照時間。例如:2024-09-10T00:00:00Z
。
建立儲存空間批次作業工作
如要建立儲存空間批次作業工作,以便處理資訊清單中包含的物件,請完成下列步驟:
指令列
-
In the Google Cloud console, activate Cloud Shell.
At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.
在開發環境中執行
gcloud storage batch-operations jobs create
指令:gcloud storage batch-operations jobs create \ JOB_ID \ --bucket=SOURCE_BUCKET_NAME \ --manifest-location=URI \ --JOB_TYPE_FLAG
其中:
JOB_ID
是儲存空間批次作業工作的名稱。SOURCE_BUCKET_NAME
是包含一或多個要處理物件的值區。例如:my-bucket
。URI
是包含資訊清單的值區 URI。例如,gs://bucket_name/path_to_csv_file/*.csv
。使用*.csv
萬用字元時,BigQuery 會將結果匯出至多個 CSV 檔案。JOB_TYPE_FLAG
是下列其中一個標記,視工作類型而定。--delete-object
:刪除一或多個物件。--put-metadata
:更新物件中繼資料。物件中繼資料會以「鍵-值」組合形式儲存。為要修改的中繼資料指定鍵/值組合。您可以將一或多個 鍵/值組合指定為清單。--rewrite-object
:更新一或多個物件的客戶自行管理的加密金鑰。--put-object-event-based-hold
:啟用事件型 物件保留。--no-put-object-event-based-hold
:停用事件型 物件保留。--put-object-temporary-hold
:啟用暫時物件保留功能。--no-put-object-temporary-hold
:停用臨時物件保留功能。
為儲存空間批次作業工作使用 Cloud 稽核記錄
儲存空間批次作業工作會記錄 Cloud Storage 物件在 Cloud Storage 稽核記錄中的轉換作業。您可以使用 Cloud 稽核記錄搭配 Cloud Storage,追蹤儲存空間批次作業工作執行的物件轉換作業。如要進一步瞭解如何啟用稽核記錄,請參閱「啟用稽核記錄」。在稽核記錄項目中,值為 StorageBatchOperations
的 callUserAgent
中繼資料欄位表示儲存空間批次作業轉換。