Google Drive 至 Google Cloud Storage 傳輸運算子¶
Google 有兩項服務用於儲存資料。Google Cloud Storage 用於儲存來自各種應用程式的大型資料。Google Drive 用於儲存日常使用資料,包括文件和相片。Google Cloud Storage 與 Google Cloud 服務有強大的整合。Google Drive 內建機制以促進群組工作,例如文件編輯器、檔案共享機制。
先決條件任務¶
若要使用這些運算子,您必須執行幾項操作
使用 Cloud Console 選擇或建立 Cloud Platform 專案。
為您的專案啟用計費功能,如 Google Cloud 文件所述。
啟用 API,如 Cloud Console 文件所述。
透過 pip 安裝 API 程式庫。
pip install 'apache-airflow[google]'詳細資訊請參閱 安裝。
運算子¶
Google Storage 和 Google Drive 之間的檔案傳輸是使用 GoogleDriveToGCSOperator
運算子執行。
複製單一檔案¶
以下運算子將單一檔案從共用 Google Drive 資料夾複製到 Google Cloud Storage Bucket。
請注意,您可以透過將共用雲端硬碟的 ID 傳遞給 folder_id
和 drive_id
參數,從共用雲端硬碟的根資料夾傳輸檔案。
upload_gdrive_to_gcs = GoogleDriveToGCSOperator(
task_id="upload_gdrive_object_to_gcs",
gcp_conn_id=CONNECTION_ID,
folder_id=FOLDER_ID,
file_name=DRIVE_FILE_NAME,
bucket_name=BUCKET_NAME,
object_name=OBJECT,
)
您可以搭配 bucket_name
、object_name
、folder_id
、file_name
、drive_id
、impersonation_chain
參數使用 Jinja 模板,讓您動態決定值。