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,
)

此条目有帮助吗?