

# Protecting your data with snapshots
Protecting data with snapshots

A *snapshot* is a read-only image of an FSx for OpenZFS volume at a point in time. Snapshots offer protection against accidental deletion or modification of files in your volumes. With snapshots, your users can easily view and restore individual folders and files from an earlier snapshot. Doing this enables users to easily undo changes and compare file versions.

Because snapshots are stored alongside your ﬁle system's data, they consume the ﬁle system's storage capacity. However, snapshots consume storage capacity only for the changed portions of ﬁles since the last snapshot.

Snapshots are stored in the `.zfs/snapshot` directory at the root of a volume.

**Topics**
+ [

## Using snapshots to create volumes
](#snapshots-volumes)
+ [

## Creating a snapshot
](#creating-snapshots)
+ [

## Deleting a snapshot
](#deleting-snapshots)
+ [

## Viewing a snapshot
](#viewing-snapshots)
+ [

## Restoring a volume from a snapshot
](#restore-volume-from-snapshot)
+ [

## Restoring individual files and folders
](#snapshots-user-restore)
+ [

# Setting up a custom snapshot schedule
](custom-snapshot-schedule.md)

## Using snapshots to create volumes


You can use a snapshot to create a clone volume or a full-copy volume.

A clone volume is a writable copy that is initialized with the same data as the snapshot from which it was created. Clone volumes provide an easy way to support multiple users or applications in parallel from a shared dataset, as well as quickly test new changes to your databases or applications. Clone volumes are created almost instantly and initially consume no additional storage capacity. (They only consume capacity for incremental changes to the source snapshot.) However, each clone volume maintains a dependency on its source snapshot, so you cannot delete this source snapshot while the clone volume is in use. To split a clone from its source snapshot and remove this dependency, you must create a new full-copy volume from that clone.

A full-copy volume is also initialized with the same data as its source snapshot, but is a fully independent writable copy. However, because a full-copy volume requires transferring all of the data from the source snapshot, it can take a significantly longer time to create than a clone volume. Once a full-copy volume is created, it is identical to a standard FSx for OpenZFS volume and does not maintain any relationship to its source snapshot.

For more information on creating clone and full-copy volumes, see [Managing Amazon FSx for OpenZFS volumes](managing-volumes.md).

## Creating a snapshot


You can create an FSx for OpenZFS snapshot using the Amazon FSx console, the Amazon CLI, and the Amazon FSx API.

### To create a snapshot (console)


1. Open the Amazon FSx console at [https://console.amazonaws.cn/fsx/](https://console.amazonaws.cn/fsx/).

1. In the left navigation pane, under **OpenZFS**, choose **Snapshots**. Then in the **Snapshots** pane, choose **Create snapshot**.

   You can also create a snapshot directly by navigating to the **Snapshots** tab of an individual volume and choosing **Create snapshot**.

1. In the **File system** field of the **Create snapshot** dialog box, choose the file system to create the snapshot on.

1. In the **Volume** field, choose an existing volume you want to take a snapshot of.

1. In the **Snapshot name** field, provide a name for the snapshot. You can use a maximum of 203 alphanumeric characters, and the special characters . - \$1 :

1. Choose **Confirm** to create the snapshot.

The snapshot is ready for use when its status is **Available**.

### To create a snapshot (CLI)

+ To create an FSx for OpenZFS snapshot, use the [create-snapshot](https://docs.amazonaws.cn/cli/latest/reference/fsx/create-snapshot.html) CLI command (or the equivalent [CreateSnapshot](https://docs.amazonaws.cn/fsx/latest/APIReference/API_CreateSnapshot.html) API operation), as shown in the following example.

  ```
  aws fsx create-snapshot \
      --volume-id fsvol-123 \
      --name snapshot2
  ```

The command example uses the following parameters:
+ `volume-id` - The ID of the volume that you are taking a snapshot of.
+ `name` - The name of the source snapshot.

After successfully creating the snapshot, Amazon FSx returns its description in JSON format.

## Deleting a snapshot


You can delete an FSx for OpenZFS snapshot using the Amazon FSx console, the Amazon CLI, and the Amazon FSx API. After deletion, the snapshot no longer exists, and its data is gone. Deleting a snapshot doesn't affect snapshots stored in a file system backup.

**Note**  
A snapshot can't be deleted if it was previously cloned and that clone is still available. Before you can delete the snapshot, you must first delete all of the snapshot's clones.

### To delete a snapshot (console)


1. Open the Amazon FSx console at [https://console.amazonaws.cn/fsx/](https://console.amazonaws.cn/fsx/).

1. In the left navigation pane, under **OpenZFS**,choose **Snapshots**.

1. In the **Snapshots** page, choose the snapshot that you want to delete.

1. In the **Summary** page for the snapshot, choose **Delete**.

### To delete a snapshot (CLI)

+ To delete an FSx for OpenZFS volume, use the [delete-volume](https://docs.amazonaws.cn/cli/latest/reference/fsx/delete-snapshot.html) CLI command (or the equivalent [DeleteVolume](https://docs.amazonaws.cn/fsx/latest/APIReference/API_DeleteSnapshot.html) API operation), as shown in the following example.

  ```
  aws fsx delete-snapshot --snapshot-id fsvolsnap-1234
  ```

## Viewing a snapshot


You can see the FSx for OpenZFS volumes that are currently on your file system using the Amazon FSx console, the Amazon CLI, and the Amazon FSx API and SDKs.

**To view the snapshots on your file system:**
+ **Using the console** – Choose a file system to view the **File systems** detail page. Choose the **Volumes** tab to list all the volumes on the file system, and then choose a volume. The volume's **Summary** page has a **Snapshots** tab that lists the snapshots for the volume.
+ **Using the CLI or API** – Use the [describe-snapshots](https://docs.amazonaws.cn/cli/latest/reference/fsx/describe-snapshots.html) CLI command or the [DescribeSnapshots](https://docs.amazonaws.cn/fsx/latest/APIReference/API_DescribeSnapshots.html) API operation.

## Restoring a volume from a snapshot


You can return a volume to a state saved by a specified snapshot. You use the [restore-volume-from-snapshot](https://docs.amazonaws.cn/cli/latest/reference/fsx/restore-volume-from-snapshot.html) CLI command (or the equivalent [RestoreVolumeFromSnapshot](https://docs.amazonaws.cn/fsx/latest/APIReference/API_RestoreVolumeFromSnapshot.html) API operation), as shown in the following example.

```
aws fsx restore-volume-from-snapshot \
    --volume-id fsvol-12345 \
    --snapshot-id fsvolsnap-67890 \
    --options DELETE_INTERMEDIATE_SNAPSHOTS DELETE_CLONED_VOLUMES
```

The command example uses the following parameters:
+ `volume-id` - The ID of the volume that you are restoring.
+ `snapshot-id` - The ID of the source snapshot. Specifies the snapshot you are restoring from.
+ `DELETE_INTERMEDIATE_SNAPSHOTS` - Deletes snapshots between the current state and the specified snapshot. `restore-volume-from-snapshot` will fail if there are intermediate snapshots and this option isn't used.
+ `DELETE_CLONED_VOLUMES` - Deletes any volumes cloned from this volume. `restore-volume-from-snapshot` will fail if there are any cloned volumes and this option isn't used.

## Restoring individual files and folders


Using the snapshots on your Amazon FSx file system, your users can quickly restore previous versions of individual files or folders. Doing this enables them to recover deleted or changed files stored on the shared file system. They do this in a self-service manner directly on their desktop without administrator assistance. This self-service approach increases productivity and reduces administrative workload.

Linux, macOS, and Windows clients can view snapshots in the `.zfs/snapshot` directory hidden at the root of a volume. The `.zfs` directory is hidden, so it will not appear in any `ls` or `dir` results. You must also specify the `crossmnt` option in the `NFS exports` configuration of your FSx for OpenZFS volume to enable your clients to navigate to this directory.

**To restore a file from a snapshot (Linux, macOS, and Windows clients)**

1. If the original file still exists and you do not want it overwritten by the file in a snapshot, then use your Linux, macOS, or Windows client to rename the original file or move it to a different directory.

1. In the `.zfs/snapshot` directory, locate the snapshot that contains the version of the file that you want to restore.

1. Copy the file from the `.zfs/snapshot` directory to the directory in which the file originally existed.

Data in snapshots is read only. If you want to make modifications to files and folders in a snapshot, you must save a copy of the files and folders to a writable location and make modifications to these copies.

# Setting up a custom snapshot schedule


You can set up a automated custom snapshot schedule for FSx for OpenZFS volumes using the resources and configuration template provided in this topic. The custom snapshot scheduling solution performs user-initiated snapshots of your Amazon FSx volumes on a custom schedule that you define. For example, you can configure a custom schedule to take a snapshot every hour and automatically delete snapshots that are older than two days.

For more information on CRON schedule patterns, see [Schedule expressions for rules](https://docs.amazonaws.cn/eventbridge/latest/userguide/eb-create-rule-schedule.html) in the *Amazon CloudWatch Events User Guide*.

## Architecture overview


Deploying this solution builds the following resources in the Amazon Web Services Cloud:

![\[Diagram showing the custom snapshot schedule Amazon CloudFormation template.\]](http://docs.amazonaws.cn/en_us/fsx/latest/OpenZFSGuide/images/openzfs-custom-snapshot-architecture.png)


The diagram illustrates the following custom snapshot schedule workflow:

1. The solution Amazon CloudFormation template deploys an CloudWatch Event, an Amazon Lambda function, an Amazon Simple Notification Service (Amazon SNS) queue, and an IAM role. The IAM role gives the Lambda function permission to invoke the necessary Amazon FSx API operations.

1. The CloudWatch event runs on a schedule you define as a CRON pattern, during the initial deployment. This event invokes the solution’s snapshot manager Lambda function that invokes the Amazon FSx `CreateSnapshot` API operation to initiate a snapshot.

1. The snapshot manager retrieves a list of existing user-initiated snapshots for the specified volume using `DescribeSnapshots`. It then deletes snapshots older than the retention period, which you specify during the initial deployment.

1. The snapshot manager sends a notification message to the Amazon SNS queue on a successful snapshot if you choose the option to be notified during the initial deployment. A notification is always sent in the event of a failure.

### Required permissions


The following permissions are required to use the custom snapshot schedule Amazon CloudFormation template:
+ `AWSCloudFormationFullAccess`
+ `AmazonS3FullAccess`
+ `AmazonEventBridgeFullAccess`
+ `IAMFullAccess`
+ `AmazonSNSFullAccess`
+ `AWSKeyManagementServicePowerUser`
+ `AWSLambda_FullAccess`

## Amazon CloudFormation template


This solution uses Amazon CloudFormation to automate the deployment of the Amazon FSx custom snapshot scheduling solution. To use this solution, download the [fsx-openzfs-scheduled-snapshot.template](https://solution-references.s3.amazonaws.com/fsx/snapshot/fsx-openzfs-scheduled-snapshot.yaml) Amazon CloudFormation template.

## Automated deployment


The following procedure configures and deploys this custom snapshot scheduling solution. It takes about five minutes to deploy. Before you start, you must have the ID of a volume on an Amazon FSx file system running in an Amazon Virtual Private Cloud (Amazon VPC) in your Amazon account. For more information on creating these resources, see [Creating an Amazon FSx for OpenZFS volume](creating-volumes.md).

**Note**  
Implementing this solution incurs billing for the associated Amazon services. For more information, see the pricing details pages for those services.

**To launch the custom snapshot solution stack**

1. Download the [fsx-openzfs-scheduled-snapshot.template](https://solution-references.s3.amazonaws.com/fsx/snapshot/fsx-openzfs-scheduled-snapshot.yaml) Amazon CloudFormation template. For more information on creating an Amazon CloudFormation stack, see [Creating a stack on the Amazon CloudFormation console](https://docs.amazonaws.cn/AWSCloudFormation/latest/UserGuide/cfn-console-create-stack.html) in the *Amazon CloudFormation User Guide*.
**Note**  
By default, this template launches in the US East (N. Virginia) Amazon Web Services Region. Amazon FSx for OpenZFS is currently only available in specific Amazon Web Services Regions. You must launch this solution in an Amazon Web Services Region where FSx for OpenZFS is available. For more information, see [Amazon FSx endpoints and quotas](https://docs.amazonaws.cn/general/latest/gr/fsxn.html) in the *Amazon Web Services General Reference*.

1. For **Parameters**, review the parameters for the template and modify them for the needs of your file system volumes. This solution uses the following default values.  
****    
[\[See the AWS documentation website for more details\]](http://docs.amazonaws.cn/en_us/fsx/latest/OpenZFSGuide/custom-snapshot-schedule.html)

1. Choose **Next**.

1. For **Options**, choose **Next**.

1. For **Review**, review and confirm the settings. Select the check box acknowledging that the template creates IAM resources.

1. Choose **Create** to deploy the stack.

You can view the status of the stack in the Amazon CloudFormation console in the **Status** column. You should see a status of **CREATE\$1COMPLETE** in about five minutes.

## Additional options


You can use the Lambda function created by this solution to perform custom scheduled snapshots of more than one FSx for OpenZFS volume. The volume ID is passed to the Amazon FSx function in the input JSON for the CloudWatch event. The default JSON passed to the Lambda function is as follows, where the values for `VolumeId` and `SuccessNotification` are passed from the parameters specified when launching the Amazon CloudFormation stack.

```
{
	"start-snapshot": "true",
	"purge-snapshots": "true",
	"volume-id": "${VolumeId}",
	"notify_on_success": "${SuccessNotification}"
}
```

To schedule snapshots for an additional FSx for OpenZFS volume, create another CloudWatch event rule. You do so using the Schedule event source, with the Lambda function created by this solution as the target. Choose **Constant (JSON text)** under **Configure Input**. For the JSON input, simply substitute the volume ID of the FSx for OpenZFS volume to back up in place of `${VolumeId}`. Also, substitute either `Yes` or `No` in place of `${SuccessNotification}` in the JSON above.

Any additional CloudWatch Event rules you create manually aren't part of the Amazon CloudFormation stack for the Amazon FSx custom scheduled snapshot solution. Thus, they aren't removed if you delete the stack.