【问题标题】:Downloading files from a GCE VM to Windows将文件从 GCE VM 下载到 Windows
【发布时间】:2020-07-16 01:30:27
【问题描述】:

我使用 Google Cloud 的 Debian GNU/Linux 9 服务器制作了一个虚拟机。在那里,我有一个脚本,可以在每天的某个时间写入并保存到 Excel (xlsx) 文件中。我安装了 tmux,这样当我关闭电脑时它会继续运行脚本。

有没有办法让我以简单的方式检索这些信息,而不必打开服务器并从那里下载。这有点违背了我制作机器人的全部目的。 :/

谢谢!

附言。我在 Windows10 桌面上

【问题讨论】:

    标签: linux windows google-cloud-platform virtual-machine google-compute-engine


    【解决方案1】:

    作为一种可能的解决方案,您可以按照以下步骤操作:

    1. create a bucketGoogle Storage

    2. installgcsfuse

    3. mount你的bucket到VM作为文件系统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.
      
    4. 检查您是否可以写入已安装的存储桶:

      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 -> 转到@987654338 @ -> 选择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
      
    5. 将 .xlsx 文件保存到挂载的存储桶(只需更改脚本中的路径)

    6. download 直接从 Windows 使用 gsutil 命令从存储桶中提取文件(gsutil 命令是 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 发送到您的虚拟机。

    【讨论】:

    • 感谢您的回答!但是,我确实相信我缺少从我的脚本中访问该挂载文件的权限。 OSError: [Errno 5] Input/output error: '/home/wmj_donkers/mount/Koersen.xlsx'。我试过sudo chmod 755 -R /home/wmj_donkers/mount,但权限再次被拒绝。
    • 我能够复制类似的错误。我已经用额外的说明更新了我的答案。
    • 非常感谢,您帮了大忙!一切似乎都在工作!我的 python 脚本正在后台运行,并且正在更新 Excel 文件。我似乎无法让我的 gsutil 命令正常工作。我认为它找不到我的 python 程序的路径。 ERROR: (gsutil) "C:\Users\User\AppData\Local\Programs\Python\Python38-32\python.exe": command not found
    • 我尝试支持您的回答,但我是该平台的新手,还没有获得 15 名声望;)
    • 谢谢!你已经接受了我的回答,我很感激。关于您与 python 相关的错误,请查看此question - 它可能对您有所帮助。
    猜你喜欢
    • 2020-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多