Technical Blog / Google Cloud Platform

GCP Filestore Snapshot Functionality — Part I

Umesh Kumhar
Google Cloud - Community
4 min readJan 3, 2023

--

This blog is about the introduction of snapshots feature in filestore and how snapshots can be created and used for restore in different scenarios. Snapshots are very beneficial in data protection and accidental deletions.

Supported tiers

The following table shows the Filestore tiers that supports snapshot as of this blog writing. Check here for latest support details.

╔════════════════╦═══════════════════╗
║ Tier ║ Snapshots support ║
╠════════════════╬═══════════════════╣
║ Basic HDD ║ No ║
║ Basic SSD ║ No ║
║ High Scale SSD ║ No ║
║ Enterprise ║ Yes ║
╚════════════════╩═══════════════════╝

Filestore Snapshot

A Filestore Snapshot is preserved state of the file share data at the time of snapshot is created. All directories in file share data contains a hidden .snapshot directory. This hidden .snapshot directory is used by snapshot functionality to preserve state of the file share data.

Behind the scenes, whenever a snapshot is triggered filestore instance only captures modified state of files and maintains under .snapshot directory. Each .snapshot directory contains the snapshots of its parent directory.

For example

fileshare-path/
│ bar.txt

└───.snapshot

├───snapshot1/
│ bar.txt

└───snapshot2/
bar.txt

Important features of snapshot:

  • All file attributes such as atime, ownership, and file permissions are preserved.
  • All snapshots of an instance share in-common data, meaning that the filestore instance preserves only the differences between the snapshots.
  • Snapshot creation usually takes no longer than two minutes to complete because it doesn’t involve the replication/copying of file share data.
  • This doesn't affect instance performance as well.
  • Snapshot functionality doesn’t consume capacity until the data on the instance is modified.

Filestore Snapshots In Action

Let's explore on how we can perform backup and restore operation using filestore snapshot on enterprise tier. These actions can be performed in different ways. In this blog we will cover using gcloud commands and via terraform snippet.

1. Create a Enterprise Filestore

Create a enterprise filestore with the minimal and required options.

Using gcloud commands:

gcloud filestore instances create test-instance \
--tier=ENTERPRISE \
--file-share=name="fileshare",capacity=1024 \
--network=name="default" \
--location="us-central1" \
--project="umeshkumhar-1"

Using terraform snippets: refer terraform doc for all options.

...

### Initialise GCP Enterprise filestore instance
resource "google_filestore_instance" "instance" {
name = "test-instance"
location = "us-central1"
tier = "ENTERPRISE"

file_shares {
capacity_gb = 1024
name = "fileshare"
}

networks {
network = "default"
modes = ["MODE_IPV4"]
}
}

...

2. Mount filestore

Once filestore is successfully created then it can be mounted on VM using mount command. You can prepare the mount point by using assigned IP address + file share path.

xx.xx.xx.xx:/fileshare
↑ ↑
ipAddresses fileshare path

The mount point details can also be found on GCP console under filestore service.

Filestore GCP Console Image

After that run the below commands on any test vm:

## Create a empty data directory 
mkdir /data

## Mount filestore mount share endpoint to local VM data directory
mount -t nfs 10.138.63.130:/fileshare /data

2. Create a snapshot

Create a filestore snapshot for testing purpose with description.

Using gcloud command:

gcloud filestore instances snapshots create fs-snapshot \
--instance=test-instance \
--instance-region=us-central1 \
--description="development purpose" \
--project=umeshkumhar-1

Using terraform snippets: refer terraform doc for all options.

...

## Create filestore snapshot resource
resource "google_filestore_snapshot" "snapshot" {
name = "fs-snapshot"
instance = google_filestore_instance.instance.name ## "test-instance"
location = "us-central1"
description = "development purpose"
}

...

Once the snapshot creation is successful, we can view the result on GCP console as well.

Snapshot Details on GCP Console

3. Restore individual files

Now let's try to restore any individual file from snapshot to the current file share.

To begin, we need to mount the filestore instance on test-vm and mount the filestore mountpoint for further actions.

As we already know that each directory has .snapshot hidden directory that contains the snapshot contents for their parent directory.

data/
│ bar.txt

└───.snapshot

├───snapshot1/
│ bar.txt

└───fs-snapshot/
bar.txt
## Mount filestore mount share endpoint to local VM data directory
mount -t nfs 10.138.63.130:/fileshare /data

## Change directory to /data
cd /data

## To restore any file just use cp command
## Restore bar.txt from fs-snapshot to current directory
sudo cp -pa ./.snapshot/fs-snapshot/bar.txt ./

## Done !!

4. Restore entire file share

Before performing the complete snapshot restore of filestore make sure all mount points are unmounted.

## Unmount the mountpoint
sudo umount /data

Using gcloud commands:

gcloud beta filestore instances revert test-instance \
--target-snapshot=fs-snapshot \
--location=us-central1 \
--project=umeshkumhar-1

Using terraform snippets: This functionality is not available via Terraform.

Thanks for reading this blog around filestore snapshot functionality. The second part of blog will describe on automating the filestore snapshot using Cloud Scheduler and Cloud Functions. Let me know if there is any feedback!

Checkout Blog Part-II.

Don’t forget to clap and follow on Medium 🙂 & also connect me on Linkedin.

--

--