简体   繁体   English

如何从GCP VM获取文件?

[英]How do I get files from GCP VM?

I currently have a GCP VM where I tried to install something and there was a no memory left error on Ubuntu. 我目前有一个GCP VM,尝试在其中安装某些东西,而Ubuntu上没有剩余内存错误。 I tried opening the SSH again and it is not working. 我尝试再次打开SSH,但无法正常工作。

PS there is no problem with firewall/connection. PS没有防火墙/连接问题。

I just want a way to download the files that I had stored in the VM. 我只想下载一种存储在VM中的文件。 Is there a way to do this without accessing the Terminal? 有没有办法在不访问终端的情况下执行此操作?

如果您无法连接到实例,则始终可以为磁盘创建快照 ,然后创建一个副本以将其安装在新实例中以从那里恢复数据。

The description and results of your problem do not make sense. 问题的描述和结果没有意义。 However, lets assume that your instance is out of memory and you cannot connect to the instance with SSH. 但是,假设您的实例内存不足,并且无法使用SSH连接到该实例。

  1. Reboot the instance and try again. 重新启动实例,然后重试。 Installing software might cause an out of memory issue. 安装软件可能会导致内存不足问题。 Rebooting should correct this. 重新启动应解决此问题。
  2. Launch the instance with a larger machine type that has more memory. 使用具有更多内存的较大计算机类型启动实例。 If this is a memory size problem, this will correct it. 如果这是内存大小问题,将对其进行纠正。
  3. Detach the instance's disk and attach to another instance that you can connect to. 分离实例的磁盘,然后附加到可以连接的另一个实例。 Mount the file system and copy off the files. 挂载文件系统并复制文件。

However, if instead your problem is out of disk space, this makes more sense. 但是,如果问题出在磁盘空间不足,则更有意义。

Resize the instance disk. 调整实例磁盘的大小。 In the Google Cloud Console, go to Compute Engine -> Disks . 在Google Cloud Console中,转到Compute Engine > Disks Click on the disk for your instance. 单击您的实例的磁盘。 Click EDIT . 点击EDIT Under Size enter a new larger disk size. Size输入新的更大的磁盘大小。 Now launch your instance. 现在启动您的实例。 For most operating systems (Ubuntu, Debian, etc.) the OS will automatically resize the root file system. 对于大多数操作系统(Ubuntu,Debian等),操作系统将自动调整根文件系统的大小。 I wrote an article that covers this in detail. 我写了一篇文章 ,详细介绍了这一点。

If you are not able to login through serial console, then the only option left would be to retrieve the data from your OLD VM by creating a new VM. 如果您无法通过串行控制台登录,则剩下的唯一选择是通过创建新VM从旧VM中检索数据。

You can follow the steps below to copy the data from the affected(OLD) VMs disk. 您可以按照以下步骤从受影响的(旧)VM磁盘中复制数据。

1 Create a snapshot from the boot disk of the OLD VM 1从OLD VM的启动磁盘创建快照

2 Create a new VM. 2创建一个新的 VM。 As a boot disk, you should use a Google public image (important- do not use the snapshot you created). 作为启动盘,您应该使用Google公共映像(重要的-不要使用您创建的快照)。

3 Once that instance is created, try to SSH into it just to test if you are able to access it. 3创建该实例后,尝试通过SSH进入该实例,以测试是否能够访问它。 There should be no issue at this point with this VM instance, as this is a new instance using a fresh operating system. 此时,此VM实例应该没有问题,因为这是使用新操作系统的新实例。

4 In the newly created instance, click on the instance name (in the Console), and then click 'Edit' at the top of the page to edit the machine. 4在新创建的实例中,单击实例名称(在控制台中),然后单击页面顶部的“编辑”以编辑计算机。

5 In the 'Additional Disks' section, click 'Add item'. 5在“其他磁盘”部分中,单击“添加项目”。

6 In the 'Name' drop-down select 'Create disk'. 6在“名称”下拉列表中,选择“创建磁盘”。 In the window that opens add a name for the disk, and in the 'Source snapshot' drop-down select the snapshot you created in Step 1. Now Click 'Create' 在打开的窗口中添加磁盘名称,然后在“源快照”下拉列表中选择在步骤1中创建快照 。现在,单击“创建”。

7 Click 'Save' to save the instances new configuration. 7单击“保存”以保存实例新配置。

8 Please SSH into the new instance, and run command $lsblk . 8请SSH进入新实例,然后运行命令$ lsblk。 You will be able to see the new disk and partition added (It will most probably be named sdb1 but you should check this and take note). 您将能够看到添加的新磁盘和分区(它很有可能被命名为sdb1,但是您应该检查并记下)。

9) Please run the following command which will create a mount point at /mnt/newdisk and then mounts the additional disk partition to that mount point. 9)请运行以下命令,该命令将在/ mnt / newdisk中创建一个安装点,然后将其他磁盘分区安装到该安装点。 Note- substitute /dev/sdb1 in the below command with the name of the partition if it is different. 注意:如果分区名称不同,则在以下命令中用分区名称替换/ dev / sdb1。

$ sudo mkdir /mnt/newdisk | $ sudo mkdir / mnt / newdisk | sudo mount -o discard,defaults /dev/sdb1 /mnt/newdisk sudo mount -o丢弃,默认为/ dev / sdb1 / mnt / newdisk

The snapshots file system will now be mounted at /mnt/newdisk. 快照文件系统现在将安装在/ mnt / newdisk。

You should now be able to navigate the directories and retrieve any data. 现在,您应该能够浏览目录并检索任何数据。

I hope this helps you. 我希望这可以帮助你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM