How to access a disk snapshot from google cloud locally?

3/9/2020

I'm using k8s on google cloud and I'm trying to use google cloud's build-in snapshotting for backups, but I would also like to use them for retrieving a db to work with locally. I've come to the conclusion that I need to first create an image of the snapshot, then export that image to a bucket before downloading. Something like this:

    gcloud compute disks snapshot mydrive --snapshot-names=mydrive-snapshot
    gcloud compute images create mydrive-image --source-snapshot mydrive-snapshot
    gcloud compute images export --destination-uri gs://my-bucket/mydrive-image.tar.gz --image mydrive-image 
    gsutil cp gs://my-bucket/my-drive-image.tar.gz file://my-drive-image.tar.gz
    tar xvf my-drive-image.tar.gz

This gives me a file disk.raw. Not sure how to mount this locally though?

Are there any other simple solutions to this? I would be fine to use a native k8s workflow instead as long as its on the volume level and doesn't involve actually running anything in a pod.

-- Viktor Hedefalk
gcloud
kubernetes

1 Answer

3/9/2020

Why not just mount the GCS bucket locally in which you exported the disk data?

You can use gcsfuse for doing this.

  1. Follow these instructions for installing Cloud Storage FUSE and its dependencies
  2. Set up credentials for Cloud Storage FUSE (follow the above instructions to do this)
  3. Create a directory (or use an already existing directory to mount the bucket)
  4. Use Cloud Storage FUSE to mount the bucket (e.g. my-bucket).

    gcsfuse my-bucket /path/to/mount
  5. Now you can see the content inside the bucket:

    ls /path/to/mount
-- Amit Yadav
Source: StackOverflow