I am using the Google cloud platform and compute engine for my project, Installed MongoDB into the instance server, what is the best way to take my database back-up and restore
my options :
- create a custom script to dump -> zip -> upload to cloud storage.
- Use GCP snapshot to back-up data and restore while a new instance creating.
Let me know the best way of handling this.
Due to the non-reliable snapshot size got confused a bit.
While schedule snapshot
2
Answers
Yes you can use snapshot. Also consider below suggestion
Use additional data disk attached to Compute Instance for Database.
In case any failure detach the disk and attach to new vm instance.
Snapshot will help you in regional failure or when you need to restore backup in another region.Also snapshot size seems confusing to you because snapshots are incremental in nature.
ex. snapshot-1 taken at 2:00 AM contains 10GB data.
now you added 1 GB data to the disk at 2:30 AM and taken snapshot again at 3:00 AM.
snapshot-2 at 3:00 AM will only contains 1 GB of data ( not 11 GB).
but real magic is when you restore snapshot-2 , it will restore your complete 11GB of data as it contains reference to snapshot-1 with 10GB data.
Yes Snapshots are reliable. You can use snapshots to create point in time image for your disk. In your case, you can take data disk snapshots. To recover data from snapshot create a disk from snapshot and attach to existing vm.
To automate mounting this you can run the gcloud commands in a bash/python script. https://cloud.google.com/compute/docs/disks/restore-snapshot#create-disk-from-snapshot
For taking regular snapshots you can setup snapshot schedule and how many times a day it should happen. To save costs you can keep retention too. https://cloud.google.com/compute/docs/disks/scheduled-snapshots