Google Cloud Storage to Google Drive Transfer Operators

Google has two services that store data. The Google Cloud Storage is used to store large data from various applications. The Google Drive is used to store daily use data, including documents and photos. Google Cloud Storage has strong integration with Google Cloud Platform services. Google Drive has built-in mechanisms to facilitate group work e.g. document editor, file sharing mechanisms.

Prerequisite Tasks

To use these operators, you must do a few things:

Operator

Transfer files between Google Storage and Google Drive is performed with the GcsToGDriveOperator operator.

You can use Jinja templating with source_bucket, source_object, destination_object parameters which allows you to dynamically determine values.

Copy single files

The following Operator would copy a single file.

airflow/contrib/example_dags/example_gcs_to_gdrive.pyView Source

copy_single_file = GcsToGDriveOperator(
    task_id="copy_single_file",
    source_bucket=GCS_TO_GDRIVE_BUCKET,
    source_object="sales/january.avro",
    destination_object="copied_sales/january-backup.avro",
)

Copy multiple files

The following Operator would copy all the multiples files (i.e. using wildcard).

airflow/contrib/example_dags/example_gcs_to_gdrive.pyView Source

copy_files = GcsToGDriveOperator(
    task_id="copy_files",
    source_bucket=GCS_TO_GDRIVE_BUCKET,
    source_object="sales/*",
    destination_object="copied_sales/",
)

Move files

Using the move_object parameter allows you to move the files. After copying the file to Google Drive, the original file from the bucket is deleted.

airflow/contrib/example_dags/example_gcs_to_gdrive.pyView Source

move_files = GcsToGDriveOperator(
    task_id="move_files",
    source_bucket=GCS_TO_GDRIVE_BUCKET,
    source_object="sales/*.avro",
    move_object=True,
)

Was this entry helpful?