将文件从 GCE VM 下载到 Windows
Downloading files from a GCE VM to Windows
我使用 Google Cloud 的 Debian GNU/Linux 9 服务器制作了一个虚拟机。在那里,我有一个脚本,每天在特定时间写入并保存到 Excel (xlsx) 文件。我安装了 tmux,这样当我关闭我的电脑时它会保留 运行 脚本。
有没有一种方法可以让我以一种简单的方式检索这些信息,而不必打开服务器并从那里下载它。这有点违背了我制作机器人的全部目的。 :/
谢谢!
Ps。我在 Windows10 桌面
作为可能的解决方案,您可以按照以下步骤操作:
install gcsfuse
mount your bucket to the VM as a file system with Cloud Storage FUSE:
bucket-fuse-mount:~$ gcsfuse bucket-fuse-mount /home/user/bucket-fuse-mount/
Using mount point: /home/user/bucket-fuse-mount
Opening GCS connection...
Opening bucket...
Mounting file system...
File system has been successfully mounted.
检查是否可以写入已安装的存储桶:
bucket-fuse-mount:~$ touch /home/user/bucket-fuse-mount/test-file
touch: cannot touch '/home/user/bucket-fuse-mount/test-file': Input/output error
如果您看到相同的错误 转到 Compute Engine
-> VM instances
-> 停止您的 VM -> 单击 NAME_OF_VM_INSTANCE
- > 单击 EDIT
-> 转到 Access scopes
-> select Set access for each API
-> 找到 Storage
并将 Read Only
更改为 Full
结果 Cloud Storage FUSE 将能够使用 Compute Engine 内置服务帐户 -> 启动 VM -> 装载存储桶并再次检查:
bucket-fuse-mount:~$ touch /home/user/bucket-fuse-mount/test-file
bucket-fuse-mount:~$
bucket-fuse-mount:~$ ls -l /home/user/bucket-fuse-mount/
total 0
-rw-r--r-- 1 user user 0 Apr 4 19:15 test-file
将 .xlsx 文件保存到已安装的存储桶(只需更改脚本中的路径)
download files from the bucket with gsutil
command directly from Windows (gsutil
command is a part of Google Cloud SDK):
gsutil cp gs://[BUCKET_NAME]/[OBJECT_NAME] [SAVE_TO_LOCATION]
对我来说它看起来像:
gsutil cp gs://bucket-fuse-mount/test-file test-file
Copying gs://bucket-fuse-mount/test-file...
/ [1 files][ 0.0 B/ 0.0 B]
Operation completed over 1 objects.
不需要连接到您的服务器。
此外,您可以用同样的方法upload文件到您的虚拟机。
我使用 Google Cloud 的 Debian GNU/Linux 9 服务器制作了一个虚拟机。在那里,我有一个脚本,每天在特定时间写入并保存到 Excel (xlsx) 文件。我安装了 tmux,这样当我关闭我的电脑时它会保留 运行 脚本。
有没有一种方法可以让我以一种简单的方式检索这些信息,而不必打开服务器并从那里下载它。这有点违背了我制作机器人的全部目的。 :/
谢谢!
Ps。我在 Windows10 桌面
作为可能的解决方案,您可以按照以下步骤操作:
install
gcsfuse
mount your bucket to the VM as a file system with Cloud Storage FUSE:
bucket-fuse-mount:~$ gcsfuse bucket-fuse-mount /home/user/bucket-fuse-mount/ Using mount point: /home/user/bucket-fuse-mount Opening GCS connection... Opening bucket... Mounting file system... File system has been successfully mounted.
检查是否可以写入已安装的存储桶:
bucket-fuse-mount:~$ touch /home/user/bucket-fuse-mount/test-file touch: cannot touch '/home/user/bucket-fuse-mount/test-file': Input/output error
如果您看到相同的错误 转到
Compute Engine
->VM instances
-> 停止您的 VM -> 单击NAME_OF_VM_INSTANCE
- > 单击EDIT
-> 转到Access scopes
-> selectSet access for each API
-> 找到Storage
并将Read Only
更改为Full
结果 Cloud Storage FUSE 将能够使用 Compute Engine 内置服务帐户 -> 启动 VM -> 装载存储桶并再次检查:bucket-fuse-mount:~$ touch /home/user/bucket-fuse-mount/test-file bucket-fuse-mount:~$ bucket-fuse-mount:~$ ls -l /home/user/bucket-fuse-mount/ total 0 -rw-r--r-- 1 user user 0 Apr 4 19:15 test-file
将 .xlsx 文件保存到已安装的存储桶(只需更改脚本中的路径)
download files from the bucket with
gsutil
command directly from Windows (gsutil
command is a part of Google Cloud SDK):gsutil cp gs://[BUCKET_NAME]/[OBJECT_NAME] [SAVE_TO_LOCATION]
对我来说它看起来像:
gsutil cp gs://bucket-fuse-mount/test-file test-file Copying gs://bucket-fuse-mount/test-file... / [1 files][ 0.0 B/ 0.0 B] Operation completed over 1 objects.
不需要连接到您的服务器。
此外,您可以用同样的方法upload文件到您的虚拟机。