Google Cloud Storage 到 Samba 的傳輸 Operator¶
Google 提供了一項服務,名為 Google Cloud Storage。這項服務用於儲存來自各種應用程式的大量資料。Samba 是用於 Linux 和 Unix 的標準 Windows 互操作性程式套件。Samba 為使用 SMB/CIFS 協議的客戶端提供了安全、穩定、快速的檔案和列印服務。
Operator¶
檔案在 Google Storage 和 Samba 之間傳輸是使用 GCSToSambaOperator operator 完成的。
將 Jinja 模板 與 source_bucket, source_object, destination_path, impersonation_chain 一起使用,以動態定義值。
複製單個檔案¶
以下 Operator 複製單個檔案。
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,
)