Copying data

Use this topic to learn how to copy data to or from a Cloud Filestore instance using the gsutil or gcloud command-line tools.

Copying data from a Cloud Storage bucket to a Cloud Filestore fileshare

You can use the gsutil rsync command to copy data from a Cloud Storage bucket to a Cloud Filestore fileshare 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. Go to the VM instances page
  2. Choose a client VM instance that has the target Cloud Filestore fileshare mounted, and then click SSH to open a terminal on that VM instance.
  3. Copy data to the mounted Cloud Filestore fileshare by running the following command, replacing [VALUES_IN_BRACKETS] with the appropriate values. 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 on which the Cloud Filestore fileshare 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. Go to the VM instances page
  2. Choose a client VM instance that has the target Cloud Filestore fileshare mapped to a drive, and then click RDP to open a remote desktop connection to that VM.
  3. Open a terminal window and run the following command to map a drive to the Cloud Filestore fileshare:

    net use [DRIVE_LETTER]: \\[IP_ADDRESS]\[FILESHARE]
    

    Where:

    • [DRIVE_LETTER] is the drive you want to map to the Cloud Filestore fileshare.
    • [IP_ADDRESS] is the IP address for the Cloud Filestore instance.
    • [FILESHARE] is the name of the fileshare on the Cloud Filestore instance.

    For example, net use Z: \\10.123.45.67\my_share.

  4. Copy data to the mapped Cloud Filestore fileshare by running the following command, replacing [VALUES_IN_BRACKETS] with the appropriate values. Use the -r option with the gsutil rsync command to recurse into subdirectories of the location you specify.

      gsutil rsync gs://[BUCKET] [MAPPED_DRIVE]
    

    Where:

    • [BUCKET] is the Cloud Storage bucket, directory, or subdirectory to copy data from.
    • [MAPPED_DRIVE] is the drive on the client to which the Cloud Filestore fileshare is mapped.

Example

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

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

Copying data from a computer in your environment to a Cloud Filestore fileshare

You can use the gcloud compute scp command to copy data from a computer in your environment to a Cloud Filestore fileshare 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. See 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 Cloud Filestore fileshare by running the following command, replacing [VALUES_IN_BRACKETS] with the appropriate values:

    gcloud compute scp [LOCAL_DATA_PATH] \
        [CLIENT_NAME]:/[MOUNT_DIRECTORY] \
        --project [PROJECT_ID] --zone [LOCATION]
    

    Where:

    • [LOCAL_DATA_PATH] is the path of a local file or directory that contains the data you want to copy to the instance. Use the --recurse flag after [LOCAL_DATA_PATH] if you want to copy data from other subdirectories.
    • [CLIENT_NAME] is the name of the client VM instance that the Cloud Filestore fileshare is mounted on.
    • [MOUNT_DIRECTORY] is the directory on the client VM instance that the Cloud Filestore fileshare is mounted on.
    • [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_NAME].
    • [LOCATION] is the GCP zone in which the client VM instance resides. You can skip this flag and use the gcloud default location 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 Cloud Filestore fileshare to a Cloud Storage bucket

You can copy data from a Cloud Filestore fileshare 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 client VM can write to Cloud Storage:

  1. Go to the VM instances page
  2. Choose a client VM instance that has the source Cloud Filestore fileshare 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 client 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 Cloud Filestore fileshare to a Cloud Storage bucket, perform the following:

Linux

  1. Go to the VM instances page
  2. Choose a client VM instance that has the source Cloud Filestore fileshare mounted, and then click SSH to open a terminal on that VM instance.
  3. Copy data from the mounted Cloud Filestore fileshare by running the following command, replacing [VALUES_IN_BRACKETS] with the appropriate values. 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 on which the Cloud Filestore fileshare 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. Go to the VM instances page
  2. Choose a client VM instance that has the source Cloud Filestore fileshare mounted, and then click RDP to open a remote desktop connection to that VM.
  3. Open a terminal window and run the following command to map a drive to the Cloud Filestore fileshare:

    net use [DRIVE_LETTER]: \\[IP_ADDRESS]\[FILESHARE]
    

    Where:

    • [DRIVE_LETTER] is the drive you want to map to the Cloud Filestore fileshare.
    • [IP_ADDRESS] is the IP address for the Cloud Filestore instance.
    • [FILESHARE] is the name of the fileshare on the instance.

    For example, net use Z: \\10.123.45.67\my_share.

  4. Copy data from the mapped Cloud Filestore fileshare by running the following command, replacing [VALUES_IN_BRACKETS] with the appropriate values. Use the -r option with the gsutil rsync command to recurse into subdirectories of the location you specify.

    Copy data from the mapped Cloud Filestore fileshare to a Cloud Storage bucket by running the following command, replacing [VALUES_IN_BRACKETS] with the appropriate values:

      gsutil rsync [MAPPED_DRIVE] gs://[BUCKET]
    

    Where:

    • [MAPPED_DRIVE] is the drive on the client to which the Cloud Filestore fileshare 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 thearchive` bucket.

gsutil rsync -r Z:\ gs://archive
หน้านี้มีประโยชน์ไหม โปรดแสดงความคิดเห็น