Why restored VM from Google cloud snapshot doesn't have data in its database?

555 views Asked by At

I'm running an web application in google compute engine and have scheduled a snapshot for the VM [Ubuntu 16.04].

I tried restoring the VM from the last available snapshot. I'm able to bring up the web application from the restored VM. But the problem is there are no any data in the database [mongodb]. All the collections created by application and default data [data seeded during deployment] are present in the mongodb in restored VM, but other than that, there is no data.

Is this how Google snapshots work? Isn't the new restored VM supposed to have all the data till the time of snapshot creation?

1

There are 1 answers

2
Wojtek_B On

Creating snapshot while all the apps are running may not prove 100% accurate because some data are in buffers / caches etc.

Your missing data might have been not yet written to the disk when the snapshot was being created.

Google documentation about creating snapshots is quite clear about it:

You can create a snapshot of a persistent disk even while your apps write data to the disk. However, you can improve snapshot consistency if you flush the disk buffers and sync your file system before you create a snapshot.

Pause apps or operating system processes that write data to that persistent disk. Then flush the disk buffers before you create the snapshot.

Try following instructions and test the results.

If for some reason you can't completely stop the database try to just flush the buffer to the disk, freeze the file system (if possible) and then create a snapshot.

You can freeze file system by logging into the instance and typing sudo fsfreeze -f [example-disk_location] and unfreeze sudo fsfreeze -u [example-disk_location].

The perfect way (with guaranteed data integrity) is to either stop the VM or unmount the disk.