flaubert
flaubert

Reputation: 593

Move file from one Google Compute Engine VM to another in the same zone?

I have 2 Google Compute Engine VMs in the same zone. How can I move a file from one VM to another?

Upvotes: 8

Views: 5885

Answers (3)

decodering
decodering

Reputation: 184

Adding on to @Faizan's answer and @irudyak's comment, an example of a full gcloud compute scp command copying a folder between VMs across different projects, and after setting up the appropriate permissions (i.e. logging in w an gcloud account with appropriate access to both projects via gcloud auth login or otherwise), would be:

gcloud compute scp --recurse example-folder --project project-b prj-b-dev-vm:/home/user/ --zone europe-west1-b --ssh-key-file ~/.ssh/id_rsa

The --ssh-key-file option is optional, and is useful if the receiving VM already has the ssh key as a known_host and in the .ssh folder (otherwise gcloud compute scp will automatically create a new ssh-key in order to access the receiving VM)

Upvotes: 1

Andrius Bertulis
Andrius Bertulis

Reputation: 29

One solution would be to move file from vm_1 to storage bucket and from storage to vm_2.

to do so in vm_1 run command gsutil cp your_file gs://your_bucket and from bucket to vm_2 in the vm_2 run command gsutil cp gs://your_bucket/your_file . This way you will have the same file backed up in a storage bucket.

Upvotes: 2

Faizan
Faizan

Reputation: 1967

You can use gcloud compute copy-files to copy data between your GCE instances or your local machine.

Upvotes: 7

Related Questions