System and user data can be excluded from snapshots by specifying exclusion patterns in an optional metadata file called
snapshots.yaml. Such exclusions can be used to control snapshot content and size.
restore command replaces the system and user data with the snapshot content which means that excluded files and directories are lost with a snapshot
The snapshots.yaml configuration file is written in YAML. It starts with the
exclude: keyword, followed by a list of shell-style wildcard (globbing) patterns to indicate which files or directories to exclude.
The following example excludes potentially cached files in
.cache, files beginning with
excl-, temporary files stored in
/tmp and files manually stored in a
The above example snapshots.yaml is taken directly from snapshot data exclusion demo.
Integrating snapshots.yaml in a snap
The snapshots.yaml file needs to be located within a snap’s
organize keyword is used to position the file under
meta/ within the snap. Alternatively, the build step override method can be used to move the file at build time:
mkdir -p $SNAPCRAFT_PART_INSTALL/meta
mv $SNAPCRAFT_PART_SRC/snapshots.yaml $SNAPCRAFT_PART_INSTALL/meta/
See the snapshot-exclude-demo for a fully functional test snap using snapshot exclusions.