Copy files from one bucket to another

The first data operation of this tutorial will consist in transferring the files from one bucket located in one GCP project to another bucket located in a different GCP project.

šŸ“„ Create a JSON file

  1. Access your tailer folder (created during installation).

  2. Create a working folder named tailer-demo for this tutorial, and inside create a folder named 1-Copy_files for this step.

  3. In your 1-Copy_files folder, create a JSON file named 000099-tailer-demo-sts.json for your data operation.

  4. Copy the following contents into your file:

    {
      "$schema": "http://jsonschema.tailer.ai/schema/storage-to-storage-veditor",
      "configuration_type": "storage-to-storage",
      "configuration_id": "000099-tailer-demo-copy-files-YOUR-NAME",
      "environment": "DEV",
      "account": "000099",
      "version": "3",
      "activated": true,
      "archived": false,
      "filename_templates": [
        {
          "filename_template": "stores-{{FD_DATE}}-{{FD_TIME}}.csv",
          "file_description": "Stores repository. The store listing is the file could evolve over time"
        },
        {
          "filename_template": "products-{{FD_DATE}}-{{FD_TIME}}.csv",
          "file_description": "Products repository. The product listing in the file could evolve over time"
        },
        {
          "filename_template": "sales_{{FD_BLOB_8}}-{{FD_DATE}}.csv",
          "file_description": "Daily Sales. There are many days in each files. And some days are repeated in different files"
        },
        {
          "filename_template": "sales_{{FD_DATE}}.csv",
          "file_description": "Daily Sales. There are many days in each files. And some days are repeated in different files"
        }
      ],
      
      "source": {
        "type": "gcs",
        "gcp_project_id": "my_gcp_project",
        "gcs_source_bucket" : "my-source-bucket",
        "gcs_source_prefix" : "input-folder-YOUR-NAME",
        "archive_prefix": "archive-folder-YOUR-NAME",
        "gcp_credentials_secret": {
          "cipher_aes": "b42xxx",
          "tag": "5c8xxx",
          "ciphertext": "fd0xxx",
          "enc_session_key": "8f6xxx"
        }
      },
      
      "destinations": [
        {
          "type": "gcs",
          "gcs_destination_bucket": "my-destination-bucket",
          "gcs_destination_prefix": "tailer-demo-input-folder-YOUR-NAME",
          "gcp_credentials_secret": {
            "cipher_aes": "b42xxx",
            "tag": "5c8xxx",
            "ciphertext": "fd0xxx",
            "enc_session_key": "8f6xxx"
          }
        }
      ]
    }
  5. Take note of the different parameters. For detailed information on storage-to-storage configuration file parameters, refer to this page.

  6. Edit the following values: ā—¾ In the source section, replace my-gcp-project with the ID of the GCP project containing your source bucket. ā—¾ In the source section, replace my-source-bucket with the name of the GCS bucket containing the source files. ā—¾ In the source section, replace the value of the gcp_credentials_secret parameter with the service account credentials for the source GCP project. If you haven't generated them yet, refer to this page. ā—¾ In the destinations section, replace my-destination-bucket with the name of the GCS bucket that will contain the output files. ā—¾ In the destinations section, replace the value of the gcp_credentials_secret parameter with the service account credentials for the destination GCP project. If you haven't done it yet, refer to this page. ā—¾ If you share the demo project with other developers, then in the configuration_id, replace YOUR-NAME by a personal value, like your name. This way, you won't overwrite a configuration deployed by someone else. You should also add your name in the source's gcs_source_prefix and archive_prefix, and in the destinations' gcs_destination_prefix to avoid any interferences with another developer's data operation.

Your JSON file is now ready to use.

ā–¶ļø Deploy a first data operation

Once your JSON file is ready, you can deploy the data operation:

  1. Access your working folder by running the following command:

    cd "[path to your tailer folder]\tailer-demo\1-Copy_files"
  2. To deploy the data operation, run the following command:

    tailer deploy configuration 000099-tailer-demo-copy-files.json

You may be asked to select a context (see this page for more information). If you haven't deployed any context, then choose "no context". You can also use the flag --context to specify the context of your choice, or NO_CONTEXT if that's what you want:

tailer deploy configuration 000099-tailer-demo-copy-files.json --context NO_CONTEXT

āœ… Check the data operation in Tailer Studio

  1. Sign in with your Tailer Platform credentials.

  2. In the left navigation menu, select Storage-to-storage.

  3. In the Configurations tab, search for your data operation. You can see its status is Activated.

  4. Click the data operation ID to display its parameters and full JSON file, or to leave comments about it.

šŸ—³ļø Check the result in GCS

Now that our configuration is deployed, we can test it. Let's mimic production behavior. Access the folders you created when preparing the demonstration environment:

  • In your source bucket, copy a file. The file name must match one of the filename_template specified in the configuration.

  • On Tailer Studio, in the Storage-to-Storage section, Runs tab, you should see a run for your data operation. It should appear as "running" and quickly get the status "success".

  • In your source bucket, input-folder should be empty.

  • In your source bucket, archive-tailer-demo-folder should contain a folder for each input file, named as the filename date.

  • In your destination bucket, input-tailer-demo-folder should contain a copy of the input files.

šŸš€ Further steps

You can see in the Storage to Storage documentation that you can handle different use cases with this data operation:

  • You can add multiple destinations to share data with different consumers.

  • You can send data to external partners. You just need a service account (or a user and a password) that can access the destination. Then you generate credentials associated with it (see documentation here) and specify it in the "destinations" object.

  • You can work with Google Cloud Storage, but also Amazon S3, Azure and SFTP.

Last updated