jacksegal/google-compute-snapshot

Wrong disk/instance detected

Closed this issue · 4 comments

When I run this script, at least this command: gcloud compute disks list --uri
.. produces a list of all the disks running in my project instead of just the disk of the VM these script is running on.

As a result, the script tries to take a snapshot of the wrong disk (the last one on the list), and incorrect permissions result in it failing.

Perhaps an option to directions to actually specify the disk/device name might be all that is needed?

Edit: I was able to get this to work using getting the device id this way:

Previous Method of getting device-name from MetaData

echo -e "$(curl -s "http://metadata.google.internal/computeMetadata/v1/instance/disks/0/device-name" -H "Metadata-Flavor: Google")"

Perhaps a note/fix update to this would be useful.

Thanks for this handy script!

I thought that might be the case - just logged on to let you know!

I introduced the new method after someone raised an issue that the meta data method was returning a disk that had been deleted - think it was a cache issue.

I'll take a look and see if I can get the new method to only get the VM - if I can't I'll just go back to using the meta data method.

@xyzulu - I've created a new branch with a fix in it (wrong-disk-detected) - are you able to try it out and see if it works for you?

Install Instructions:

cd ~
wget https://raw.githubusercontent.com/jacksegal/google-compute-snapshot/wrong-disk-detected/gcloud-snapshot.sh
chmod +x gcloud-snapshot.sh
sudo mkdir -p /opt/google-compute-snapshot
sudo mv gcloud-snapshot.sh /opt/google-compute-snapshot/
sudo /opt/google-compute-snapshot/gcloud-snapshot.sh

Rollback to Master Instructions (you'll need to change the line in the getDeviceName function again):

cd ~
wget https://raw.githubusercontent.com/jacksegal/google-compute-snapshot/master/gcloud-snapshot.sh
chmod +x gcloud-snapshot.sh
sudo mkdir -p /opt/google-compute-snapshot
sudo mv gcloud-snapshot.sh /opt/google-compute-snapshot/

Yip, that works perfectly now
Thanks!