如何在命令行上 rsync 到 Google Cloud VM 实例
如果你想使用 SSH 从命令行连接到 Google Cloud VM 实例(在此示例中为 my-instance),使用此命令:
rsync_gcloud.sh
rsync -Pavz [local file] $(gcloud compute instances list --filter="name=my-instance" --format "get(networkInterfaces[0].accessConfigs[0].natIP)"):子命令(包含在 $(...) 中)查找你实例的正确外部 IP 地址(请参见如何在命令行上查找 Google Cloud VM 实例的 IP 地址了解更多详情),所以此命令简化为例如
rsync_gcloud_example.sh
rsync -Pavz [local file] 35.207.77.101:使用 -Pavz 选项不是特别必要,但这些是我经常用于 rsync 文件传输的选项。你可以使用任何 rsync 选项,Google Cloud 不施加任何特定限制。供参考请参见 rsync 手册页。
如果你想为 SSH 登录使用不同的用户名,你当然可以像这样在 $(...) 部分前添加前缀:
rsync_gcloud_user.sh
rsync -Pavz [local file] sshuser@$(gcloud compute instances list --filter="name=my-instance" --format "get(networkInterfaces[0].accessConfigs[0].natIP)"):Check out similar posts by category:
Cloud
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow