Pramod Anantha
Pramod Anantha

Reputation: 39

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. I tried opening the SSH again and it is not working.

P.S there is no problem with firewall/connection.

I just want a way to download the files that I had stored in the VM. Is there a way to do this without accessing the Terminal?

Upvotes: 2

Views: 3367

Answers (3)

Digil
Digil

Reputation: 752

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.

You can follow the steps below to copy the data from the affected(OLD) VMs disk.

1 Create a snapshot from the boot disk of the OLD VM

2 Create a new VM. As a boot disk, you should use a Google public image (important- do not use the snapshot you created).

3 Once that instance is created, try to SSH into it just to test if you are able to access it. There should be no issue at this point with this VM instance, as this is a new instance using a fresh operating system.

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.

5 In the ‘Additional Disks’ section, click ‘Add item’.

6 In the ‘Name’ drop-down select ‘Create disk’. 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’

7 Click ‘Save’ to save the instances new configuration.

8 Please SSH into the new instance, and run command $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).

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. Note- substitute /dev/sdb1 in the below command with the name of the partition if it is different.

$ sudo mkdir /mnt/newdisk | sudo mount -o discard,defaults /dev/sdb1 /mnt/newdisk

The snapshots file system will now be mounted at /mnt/newdisk.

You should now be able to navigate the directories and retrieve any data.

I hope this helps you.

Upvotes: 5

Rafa Diaz
Rafa Diaz

Reputation: 46

If you can't connect to the instance you always can take a snapshot of the disk and then create a copy to mount it in a new instance to recover the data from there.

Upvotes: 0

John Hanley
John Hanley

Reputation: 81386

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.

  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. Click on the disk for your instance. Click EDIT. Under Size enter a new larger disk size. Now launch your instance. For most operating systems (Ubuntu, Debian, etc.) the OS will automatically resize the root file system. I wrote an article that covers this in detail.

Upvotes: 0

Related Questions