Sudesh
Sudesh

Reputation: 77

Transfer files from one VM to another in GCP CE

I am trying to move a file from one VM instance to another using scp method. However I had understood that it is not possible to do the direct transfer from the source instance. e.g scp db.sql user@instance-src:/home/data/db.sql

I tried using the gcloud scp command but this allows me to do a transfer from local to remote only. This means I need to first download the file from the source to local.

Is there a better way to do this task?

Upvotes: 3

Views: 2811

Answers (2)

Mahboob
Mahboob

Reputation: 1975

First you need to create public key on the source-vm using the command ssh-keygen then you can see the public key using the command cat .ssh/id_rsa.pub. Now add the public key of source VM instance to the /home/user-name/.ssh/authorized_keys of destination vm instance. Now, you can transfer the files from the source-vm to the destination-vm as @Johnhanley said.

Alternatively, using the below command you can transfer the file from one VM to another VM using below gcloud command:

gcloud compute ssh source-vm --command='scp db.sql user@destination-vm:/home/file-transfer-location --zone=us-central1-a'

Upvotes: 4

jccampanero
jccampanero

Reputation: 53441

Instead of using ssh maybe a simpler option could be using a GCS bucket as intermediate, temporal, storage in the copy process.

The gcloud CLI and the companion gsutil tool used for that purpose should be installed in every VM.

Please, be aware that you need to grant write access to the bucket to the Compute Engine default service account for this setup work properly.

Upvotes: 1

Related Questions