ZFS File System & Snapshot Management

ZFS File System & Snapshot Management

Hey everyone!

Hope you are doing great!

In this topic, I want to put some light on ZFS file system management, especially within Ubuntu systems.

ZFS file system was created for secure and reliable system management via automatic and manual snapshots creating.

Snapshots provide main two powerful possibilities:

  1. Revert the system OR some folder (snapshot directory) back if something fails.
  2. Scrubbing data on weekly or monthly bases to control the integrity of your and system files.

1. How to set ZFS on Ubuntu from the scratch

If you want to set up ZFS from the scratch with a new Ubuntu installation, you can follow this

1.1. Click Advanced features

1.2. Chose Erase disk and use ZFS

1.3. And confirm the installation

2. How to manage ZFS on your machine

2.1. Start terminal
2.2. Checking status

zpool status

2.3. Listing ZFS pools

zpool list

2.4. List directories which setup for snapshot creating

zfs list

3. How to deal with lack of free space on ZFS machine even after files deleted

Sometimes after working with your machine for a while with ZFS file system, you will face that deletion files will not make free space. Because deleted data will remain on previously created snapshots. So maybe you will want to delete them.

4. How to delete all snapshots of your username directory

Method 1

zfs list -H -t snapshot -o name -S creation rpool/USERDATA/example_username | tail -n 3 | sudo xargs -n 1 zfs destroy -v

Where you need to change example_username to your username in your system.

Test it with

zfs list -H -t snapshot -o name -S creation rpool/USERDATA/example_username | tail -n 3 | sudo xargs -n 1 echo

This command will delete the three oldest snapshots of your user home directory.

Method 2

zfs list -H -t snapshot -o name -S creation | grep example_username | tail -n 3 | sudo xargs -n 1 zfs destroy -v

Where you need to change example_username to your username in your system.

Test it with

zfs list -H -t snapshot -o name -S creation | grep example_username | tail -n 3 | sudo xargs -n 1 echo

This command will delete the three oldest snapshots of your user home directory.

You are awesome!

That is it. Hope this short guide helped you and saved your time for the best.

Thank you for reading and see you soon.