0
votes

I had one disk attached to an instance & i had taken snapshot of it. Now, after few days - the disk went bad and i want to restore the disk. What i have implemented is :

  1. Store metadata of snapshot, when taken
  2. When restore request comes, i create new disk from snapshot
  3. detach original disk (say attached inside host as /dev/sdz )
  4. attach Newly created disk to the same instance

With this way, the user will get the view that the disk has been restored using the snapshot he had taken.

Now, the problem i'm seeing with this approach is : as the original disk was attached as /dev/sdz, after detach & attach of NEW disk, the new disk should be seen as /dev/sdz ONLY, Otherwise the application or upper-layers may break.

So, is there any provision that google-cloud APIs provide to handle this ?

PLEASE NOTE: I'm using google-api-python-client library & code is in Python.

1
Set your fstab to mount disks depending on the UUID. If you make a disk image in GCP and create a new disk from it it will maintain the UUID, and thus, the device entry point. Example:"UUID=1123c451-a8f8-42af-9988-ebb42e0f7051 /mnt/backup/snapshots ext4 defaults 1 1" However, you should never manage linux servers on the cloud if you dont perfectly know what you're doing, you should advice your boss to get an IT guy to do it tempraly while teaching you and leave you with taks you know how to properly achieve. This is VERY dangerous for you to temper with things you're clearly not an expert in. - DGoiko
I'm saying this because a mistake in the cloud is normally much harder to recover from, and will probably get you instantly fired because of the huge damage you can cause to your company. If this is a house-project then its okey you try to learn the hard way. Oh, and i'd advice not using python for critital operation applications, such as backup restore or data tempering, but thats just about personal experiences doing things the fast and easy way rather than the proper one. "ls -l /dev/disk/by-*/" is your friend. - DGoiko

1 Answers

1
votes

I believe the name you are referring to is the "index" of the disk. I am not sure of that however. If that is the case, you would just need to make sure the index of the new disk matches the index of the disk you remove.

That being said, there are better ways to do this if you can modify your fstab. For example, you can use the "deviceName" by mounting /dev/disk/by-id/whatever in which case you would just need to make sure that the new disk has the same deviceName as the old disk.


Another option is to use the UUID of the filesystem to mount. Since these new disks are snapshots of the old disk, they will have the same UUID.

ls -l /dev/disk/by-uuid/

That should not change unless you reformat the partition entirely. In your fstab, instead of /dev/sdz1, you would use UUID=ef7481ea-a6f9-425b-940f-56e9c93492dd or whatever.