Search code examples
gcloud

How to move files between two VMs using gcloud?


I have tried using scp provided by , however, that produces an error:

gcloud compute scp github-action-runner-0001:/tmp/images.tar github-action-runner-0002:/tmp/images.tar
ERROR: (gcloud.compute.scp) All sources must be local files when destination is remote.  Got sources: [github-action-runner-0001:/tmp/images.tar], destination: github-action-runner-0002:/tmp/images.tar

I am evaluating if there are alternative ways of copying files from one VM to another using gcloud utilities.

Obviously, copying files locally first would work, however, given the size of the files this would not work reliably.


Solution

  • Imagine you have two Compute Engine virtual machines: VM-A and VM-B.

    1. SSH login to VM-A.
    2. Use the gcloud compute scp command to copy files to/from VM-B.

    By logging into VM-A, it becomes the local system and VM-B becomes the remote system.

    Note: Your question does not specify what github-action-runner-0001 is. I m assuming that it is the name of a Compute Engine VM. If it is not, then complete step #1 and then copy the files from github-action-runner-0001 to VM-A and then copy the files from VM-A to VM-B using step 2.