Copying data

This page shows you how to copy data from:

  • Cloud Storage buckets to Filestore file shares.
  • Computers in your environment to Filestore file shares.
  • Filestore file shares to Cloud Storage buckets.

To follow these instructions, you will need the gsutil and gcloud command-line tools.

Copying data from a Cloud Storage bucket to a Filestore file share

You can use the gsutil rsync command to copy data from a Cloud Storage bucket to a Filestore file share that is mounted on a Compute Engine VM instance. The gsutil rsync command works on both Linux and Windows VMs. On Linux VM instances, you can also use standard commands like rsync to copy data.

Linux

  1. In the Cloud Console, go to the VM Instances page.

    Go to the Compute Engine instances page

  2. Choose a Compute Engine VM instance that has the target Filestore file share mounted and click SSH to open a terminal on that VM instance.

  3. Copy data to the mounted Filestore file share by running the following command. You can use the -r option with the gsutil rsync command to recurse into subdirectories of the location you specify.

    gsutil rsync gs://bucket mount-directory
    

    where:

    • bucket is the Cloud Storage bucket, directory, or subdirectory to copy data from.
    • mount-directory is the directory on the client where the Filestore file share is mounted.

Example

The following command copies data from the data bucket and all subdirectories to the /mnt/filer directory.

gsutil rsync -r gs://data /mnt/filer

Windows

  1. In the Cloud Console, go to the VM Instances page.

    Go to the Compute Engine instances page

  2. Choose a Compute Engine VM instance that has the target Filestore file share mapped to a drive and click RDP to open a remote desktop connection to that VM.

  3. Copy data to the mapped Filestore file share by running the following command. You can use the -r option with the gsutil rsync command to recurse into subdirectories of the location you specify.

    gsutil rsync gs://bucket mount-directory
    

    where:

    • bucket is the Cloud Storage bucket, directory, or subdirectory to copy data from.
    • mount-directory is the directory on the client where the Filestore file share is mounted.

Example

The following command copies data from the data bucket and all subdirectories to the Z: drive that is mapped to the Filestore file share.

gsutil rsync -r gs://data Z:\

Copying data from a computer in your environment to a Filestore file share

You can use the gcloud compute scp command to copy data from a computer in your environment to a Filestore file share that is mounted on a Compute Engine Linux VM instance. The gcloud compute scp command doesn't work on Windows VM instances.

  1. Use SSH to connect to the computer that contains the data you want to copy.
  2. Check if you have the gcloud tool installed by running the following command:

     which gcloud
    

    The command returns the installation path if the gcloud tool is installed. If no installation path is returned, follow the instructions at Installing Cloud SDK to install it.

  3. Copy data to the mounted Filestore file share:

     gcloud compute scp local-data-path client-name:/mount-directory --project=project-id --zone=zone
    

    where:

    • local-data-path is the path of a local file or directory that contains the data you want to copy to the instance. You can use the --recurse flag after local-data-path if you want to copy data from other subdirectories.
    • client-name is the name of the Compute Engine VM instance that the Filestore file share is mounted on.
    • mount-directory is the directory on the client where the Filestore file share is mounted.
    • project-id is the ID of the GCP project that contains the client VM instance. You can skip this flag and use the gcloud default project instead if you have set it by using gcloud config set project project-id.
    • zone is the GCP zone in which the Compute Engine VM instance resides. You can skip this flag and use the gcloud default zone instead if you have set it by using gcloud config set compute/zone zone.

Example

The following command copies data from the local /etc/acme/data directory and its subdirectories to the /mnt/filer directory on the nfs-client VM instance, in the myproject project, in zone us-central1-c:

gcloud compute scp /etc/acme/data --recurse nfs-client:/mnt/filer --project myproject --zone us-central1-c

Copying data from a Filestore file share to a Cloud Storage bucket

You can copy data from a Filestore file share that is mounted on a Compute Engine VM instance to a Cloud Storage bucket by using the gsutil rsync command.

Before proceeding, first make sure that the Compute Engine VM can write to Cloud Storage:

  1. In the Cloud Console, go to the VM Instances page.

    Go to the Compute Engine instances page

  2. Choose a Compute Engine VM instance that has the source Filestore file share mounted.

  3. Check if the instance has Read Write scope:

    1. Click the instance name to open the instance details page.
    2. Expand Cloud API access scopes and see if Storage has Read Write scope.

If the Compute Engine VM doesn't have Read Write scope, perform the following steps:

  1. Click Stop at the top of the page to stop the instance.
  2. When the instance has stopped, click Edit at the top of the page.
  3. Under Access scopes, select Set access for each API.
  4. Under Storage, select Read Write, and click Save.
  5. When the instance finishes updating, click Start at the top of the page.

To copy data from a Filestore file share to a Cloud Storage bucket, perform the following:

Linux

  1. In the Cloud Console, go to the VM Instances page.

    Go to the Compute Engine instances page

  2. Choose a Compute Engine VM instance that has the source Filestore file share mounted, and then click SSH to open a terminal on that VM instance.

  3. Copy data from the mounted Filestore file share by running the following command. You can use the -r option with the gsutil rsync command to recurse into subdirectories of the location you specify.

    gsutil rsync mount-directory gs://bucket
    

    where:

    • mount-directory is the directory on the client where the Filestore file share is mounted.
    • bucket is the Cloud Storage bucket, directory, or subdirectory to copy data to.

Example

The following command copies data from the /mnt/filer directory and all subdirectories to the archive bucket.

gsutil rsync -r /mnt/filer gs://archive

Windows

  1. In the Cloud Console, go to the VM Instances page.

    Go to the Compute Engine instances page

  2. Choose a Compute Engine VM instance that has the source Filestore file share mounted, and then click RDP to open a remote desktop connection to that VM.

  3. Copy data from the mapped Filestore file share by running the following command. You can use the -r option with the gsutil rsync command to recurse into subdirectories of the location you specify.

    gsutil rsync mapped-drive gs://bucket
    

    where:

    • mapped-drive is the drive on the client to which the Filestore file share is mapped.
    • bucket is the Cloud Storage bucket, directory, or subdirectory to copy data to.

Example

The following command copies data from the mapped drive Z: and all subdirectories to the archive bucket.

gsutil rsync -r Z:\ gs://archive