ZFS Snapshots Explained: Learn how ZFS snapshots work and how they provide instant access to previous versions of your files without complex recovery procedures.
What you’ll learn in this video:
- How to create ZFS snapshots of your data
- Understanding ZFS snapshot naming conventions
- Accessing the hidden .zfs/snapshot directory
- Browsing through snapshot directories like a time machine
- Viewing previous file versions from any snapshot
- Understanding how snapshots preserve data over time
- Cleaning up snapshots with zfs destroy command
- How live filesystem changes don’t affect existing snapshots
ZFS snapshots provide instant access to previous versions of your files through a simple directory path. Unlike traditional backup systems, snapshots are read-only point-in-time copies that allow you to browse and recover files instantly without complex restore procedures.
📝 Video Transcript
00:00 – Introduction
Welcome to linuxconfig.org. In this tutorial, we’ll explore ZFS snapshots and how they provide instant access to previous versions of your files. We’ll create multiple snapshots, browse through them like a time machine, and see how easy it is to view any previous version of your data.
00:30 – Verifying ZFS Pool Configuration
Before we can continue, we need to verify our ZFS pool configuration and check our existing data sets. First, we’ll use zpool –version to confirm ZFS is installed and check the version. Then we’ll run zpool status to verify our pool named zfspool is online and see that it’s using disk SDB. Next, we’ll use zfs list to view our data sets including the linuxconfig mounted at /zfspool/linuxconfig. Keep in mind, your output will be different depending on your specific ZFS setup, pool names, and disk configuration.
01:11 – Creating Multiple Snapshots Over Time
We’ll now create a simple document and capture three different versions using ZFS snapshots. First, we navigate to our ZFS pool at /zfspool/linuxconfig. We create a file called document.txt with the content version 1 and immediately take our first snapshot named ep3_v1. Notice the snapshot naming convention. We use the @ sign to separate the data set name from the snapshot name. Next, we update the document to version 2 and create a second snapshot called ep3_v2. Finally, we change the content to version 3 and take our third snapshot, ep3_v3. Each snapshot captures the exact state of our file system at that moment in time, preserving every version of our document.
02:20 – Browsing and Accessing Snapshots
Now, let’s see how to access our snapshots. ZFS stores snapshots in a hidden directory called .zfs/snapshot under each data set. When we list the contents of /zfspool/linuxconfig/.zfs/snapshot, we can see all three snapshots we just created – ep3_v1, v2, and v3. Each snapshot appears as a regular directory that we can browse into. To view the content from our first snapshot, we use cat to read /zfspool/linuxconfig/.zfs/snapshot/ep3_v1/document.txt and we see version 1. Similarly reading from ep3_v2 shows version 2 and ep3_v3 shows version 3. This is the power of ZFS snapshots. Every previous version of your files is instantly accessible through a simple file path. No complex restore process needed.
03:29 – Current Version and Snapshot Comparison
When we check the current version of our document in the active file system, we see version 3, which is the latest change we made. Notice how the snapshots preserve all previous versions, while the live file system continues to change. Each file version remains directly accessible through the snapshot directory, and you can perform a rollback to restore your entire dataset to any previous snapshot state. However, snapshot rollback techniques are beyond the scope of this short tutorial. We’re simply demonstrating how snapshots capture and preserve your data over time.
04:13 – Cleanup
Now let’s clean up our demonstration. We delete each snapshot using the zfs destroy command followed by the full snapshot name zfspool/linuxconfig@ep3_v1, v2 and v3. After destroying all snapshots, our document.txt still exists with version 3, showing that destroying snapshots only removes the snapshot history, not the current data. Subscribe for more Linux tutorials, and thanks for watching.