Monday 2 April 2018

linux - How can I copy files from a Google Cloud Compute Server to my local machine


I'm trying to download all of the server files from Google Cloud Compute (running Linux Debian). I'm extremely unfamiliar with SSH and Google Cloud Compute as a whole. I'd prefer either copying all of the files (similar to a git pull request) or creating a zip and downloading. In short I need to copy all of the files on the remove Google Cloud server to my local machine.


Thank you in advance.



Answer



Try using gcloud compute scp:


gcloud compute scp 
[[USER@]INSTANCE:]SRC [[[USER@]INSTANCE:]SRC …]
[[USER@]INSTANCE:]DEST
[--compress] [--dry-run] [--force-key-file-overwrite]
[--plain] [--port=PORT] [--recurse] [--scp-flag=SCP_FLAG]
[--ssh-key-file=SSH_KEY_FILE]
[--strict-host-key-checking=STRICT_HOST_KEY_CHECKING]
[--zone=ZONE]
[GCLOUD_WIDE_FLAG …]
[-h]

e.g.,


$ gcloud compute scp \
my-instance-1:~/file-1 \
my-instance-2:~/file-2 \
~/my-destination \
--zone us-central2-a

As an alternative, you can also use (non-gcloud) sftp or scp; see this SO answer for details on the command line arguments you need to specify, which I'll quote here for simplicity:


sftp -o IdentityFile ~/.ssh/google_compute_engine user@host

To use any other SFTP tool, similarly provide to it the path to the SSH private key and it will be able to connect to the instance. However, in the case of gcloud, it can resolve the hostname to the public IP themselves; for all other tools, you'll need to find the IP manually and specify the IP address directly.


No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...