Google Cloud Storage Transfer Operator to Samba¶
Google 提供了一项服务 Google Cloud Storage。该服务用于存储来自各种应用的大量数据。Samba 是 Linux 和 Unix 上的标准 Windows 互操作程序套件。Samba 为使用 SMB/CIFS 协议的客户端提供安全、稳定且快速的文件和打印服务
操作符¶
在 Google Storage 与 Samba 之间传输文件可使用 GCSToSambaOperator 操作符。
使用 Jinja 模板 与 source_bucket, source_object, destination_path, impersonation_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,
)