Google Cloud Storage Transfer Operator 至 Samba

Google 有一項服務 Google Cloud Storage。此服務用於儲存來自各種應用程式的大量資料。Samba 是適用於 Linux 和 Unix 的標準 Windows 互通性程式套件。Samba 為使用 SMB/CIFS 通訊協定的用戶端提供安全、穩定且快速的檔案和列印服務

運算子

Google Storage 和 Samba 之間的檔案傳輸是透過 GCSToSambaOperator 運算子執行。

使用 (在 apache-airflow v3.0.0.dev0) Jinja 模板source_bucketsource_objectdestination_pathimpersonation_chain 來動態定義值。

複製單一檔案

以下運算子複製單一檔案。

tests/system/samba/example_gcs_to_samba.py[原始碼]

copy_file_from_gcs_to_samba = GCSToSambaOperator(
    task_id="file-copy-gcs-to-samba",
    samba_conn_id=SMB_CONN,
    source_bucket=BUCKET_NAME,
    source_object=GCS_SRC_FILE,
    destination_path=DESTINATION_PATH_1,
)

移動單一檔案

若要移動檔案,請使用 move_object 參數。檔案複製到 SMB 後,Google Storage 中的原始檔案將會被刪除。destination_path 參數定義 Samba 伺服器上檔案的完整路徑。

tests/system/samba/example_gcs_to_samba.py[原始碼]

move_file_from_gcs_to_samba = GCSToSambaOperator(
    task_id="file-move-gcs-to-samba",
    samba_conn_id=SMB_CONN,
    source_bucket=BUCKET_NAME,
    source_object=GCS_SRC_FILE_IN_DIR,
    destination_path=DESTINATION_PATH_1,
    move_object=True,
)

複製目錄

source_path 參數中使用 wildcard 以複製目錄。

tests/system/samba/example_gcs_to_samba.py[原始碼]

copy_dir_from_gcs_to_samba = GCSToSambaOperator(
    task_id="dir-copy-gcs-to-samba",
    samba_conn_id=SMB_CONN,
    source_bucket=BUCKET_NAME,
    source_object=GCS_SRC_DIR,
    destination_path=DESTINATION_PATH_2,
)

移動特定檔案

source_path 參數中使用 wildcard 以移動特定檔案。destination_path 定義前置於所有複製檔案的路徑。

tests/system/samba/example_gcs_to_samba.py[原始碼]

move_dir_from_gcs_to_samba = GCSToSambaOperator(
    task_id="dir-move-gcs-to-samba",
    samba_conn_id=SMB_CONN,
    source_bucket=BUCKET_NAME,
    source_object=GCS_SRC_DIR,
    destination_path=DESTINATION_PATH_3,
    keep_directory_structure=False,
)

這個條目對您有幫助嗎?