Skip to content
View in the app

A better way to browse. Learn more.

Unraid

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

How to delete every snapshot on my ZFS cache?

Featured Replies

I use my two nvme Cache Drives with ZFS and made some Snapshots. How can I delete EVERY Snapshot in my System Folder?

 

SCR-20250203-tyyw-4.png

Edited by unrd44

  • Community Expert

while I wouldn't destroy the .system snapshot as it does hold settings for zfs as that is a remneat of a import from truenas into unraid...

you can run the zfs destroy -r to kill the entire dataset system and snapshots...

I don't remember the terminal command offhand that targes snapshots only...

Unraid zfs master plugin also has a snapshot admin where you can select your snapshot and delete it.
image.png.2253534613000e3f65102d9b9b251b09.png

 

select all at top delete button:
image.png.16d83a83b7b196ac94d1c42668d5bad8.png

  • Author

Thanks for your answer.

In Snapshot Admin i do not get the whole tree, when i select the top entry...

2025-02-04 11_08_40.png

  • Community Expert

ok then lets see if this works as intended for you...
as i'm lacking some data to make a script...

I will pull from my backup the prune command and attempt to grab the entire dataset to kill all snapshots...

# Function to prune snapshots
prune_snapshots() {
  local DATASET="$1"
  local KEEP="${SNAPSHOT_QTY}"
  
  local SNAPSHOTS=( $(zfs list -t snapshot -o name -s creation -r "${DATASET}" | grep "^${DATASET}@") )
  local SNAPSHOTS_COUNT=${#SNAPSHOTS[@]}

  echo "Total snapshots for ${DATASET}: ${SNAPSHOTS_COUNT}"

  local SNAPSHOTS_SPACE
  SNAPSHOTS_SPACE=$(zfs get -H -o value usedbysnapshots "${DATASET}")
  echo "Space used by snapshots for ${DATASET}: ${SNAPSHOTS_SPACE}"

  if [[ ${SNAPSHOTS_COUNT} -gt ${KEEP} ]]; then
    local TO_DELETE=$((SNAPSHOTS_COUNT - KEEP))
    for i in "${SNAPSHOTS[@]:0:${TO_DELETE}}"; do
      zfs destroy "${i}"
      echo "Deleted snapshot: ${i}"
      echo "_____________________________________________________________"
    done
  else
   echo "_____________________________________________________________"
  fi

per some of my workarounds and script... 

 

step 1 we will need a list that zfs is seeing. you may be fighting zfs acl and linux ownership and file access permission...
 

# List all datasets, particularly focusing on the `.system` dataset
zfs list -t snapshot -r $(zfs list -H -o name | grep -m 1 '.system')

List all datasets and snapshots
We need to grab the full list of datasets, especially focusing on .system and its snapshots. This command can identify and list them all.

step 2. delete the listed snapshots:

 

# Example script to delete snapshots within `.system`
SYSTEM_DATASET=$(zfs list -H -o name | grep -m 1 '.system')
zfs list -t snapshot -r "$SYSTEM_DATASET" | awk '{print $1}' | while read SNAP; do
    echo "Destroying snapshot: $SNAP"
    zfs destroy "$SNAP"
done


step 3 set acl/permissions..

Fixing permissions and ACLs Unraid requires that files and directories be accessible to the nobody user and users group. Reapplying correct permissions can solve access issues.

SYSTEM_DATASET=$(zfs list -H -o name | grep -m 1 '.system')

# Change ownership to Unraid-friendly user and group
chown -R nobody:users "/mnt/$SYSTEM_DATASET"

# Apply full permissions to allow access
chmod -R 777 "/mnt/$SYSTEM_DATASET"

*As I did turenas original, went back and forth to unraid. Was on unraid for a long while and recently moved my pool into truenas and into unraid again to collect what goes wrong

 

where and how to fix this... Truenas makes .system dataset and stores truenas and other zfs related data there. Moving uraid to truenas there is an issue on how the dataset and mount point is set. It can be a pain to move from unriad into truenas...

Unraid uses the nobody user and user group for just about everything, setting these acl and permission will help access manipulate and do things to the system. 

With dataset and setting permission, you may see read only file system. That is normal based on zfs acl permission...

# Verify that snapshots are gone and permissions are set correctly
 

zfs list -t snapshot -r "$SYSTEM_DATASET"
ls -l "/mnt/$SYSTEM_DATASET"



You will need to get the full zfs path and use the zfs destroy command
more info here:
https://openzfs.github.io/openzfs-docs/man/master/8/zfs-destroy.8.html

Edited by bmartino1
typo

  • Author

@bmartino1 Thanks for the Script. How can i execute that? With the user script Plugin in Unraid? What Dows "legacy" and the yellow camera icon mean?

SCR-20250205-nvev-2.png

  • Community Expert
5 hours ago, unrd44 said:

@bmartino1 Thanks for the Script. How can i execute that? With the user script Plugin in Unraid? What Dows "legacy" and the yellow camera icon mean?

SCR-20250205-nvev-2.png

User Plugin is preferd...

 

The ZFS master plug-in has a warning system of 30 days default 
image.thumb.png.d6b84963461b78ff016a7681db2299f2.png

Settings> ZFS Master

 

If you have content that has a snapshot or needs to be snapshot for ZFS bit rot protection, it will turn yellow based on how long it was since last snapshot. Letting you know that it's time to make a new snapshot and/or verify your data. 


How to explain the legacy info....

The legacy option is just an old format on how ZFS was using .system dataset in order to store and use some of zfs configurations...

The legacy system for ZFS was used to store and pull the information. It's marked as legacy more to the note that it was never mounted as it does contain data and is considered a dataset...

 

Review:

What is a ZFS legacy mount point

http://superuser.com/questions/790036/ddg#1557822

 

ZFS provides a hierarchical structure of datasets within a pool. In example case you have a pool named rpool, and at least the following datasets:

rpool

rpool/ROOT

rpool/ROOT/s10x_u10_wos_17b

Each of these datasets is often a filesystem (though it can be a volume / block device instead)...

 

Just as each of these is datasets is likely a full / independent filesystem, each can also be mounted or not mounted independently.

By default, ZFS will mount children datasets at their logical location within the parent... If the rpool dataset is mounted at /rpool (i.e: default), then you would find that the rpool/ROOT dataset mounted at /rpool/ROOT, etc...

 

This is controlled by the mountpoint property - run 

zfs get -rt

filesystem mountpoint to see its current value for each dataset.

 

If the value is a path, then ZFS will automatically mount the dataset at that path when the pool is imported. The default (as mentioned above) is to mount the filesystem under the parent. (usualy /mnt/<poolname> and then /mnt/<poolname>/<Dataset_name>)

 

If the value is none, then ZFS will not mount the filesystem, and the filesystem cannot be mounted using mount either.

If the value is legacy, then ZFS will not mount the filesystem, but you can use mount and umount to manage the filesystem's mountpoint manually. On other Linux Distros, You could use /etc/fstab to guide automatic mounting.

 

Edited by bmartino1
typo - Data

  • Community Expert

The easiest way is to run the code is via the user script plug-in yes...

 

However, you can make an sh script in terminal stored anywhere and run the script. 

 

Sometime:

Or simply copy paste the entire script and it will run.

  • Author

@bmartino1 Thank you for your Script and explains! When i run the Script i get the following error Messages. In the past i used Docker Directories, now i use Docker Image. I think this is old stuff... What can i do to get a clean system Share?

 

 

2025-02-11 12_05_00.png

  • Author

Solved! I user the following Script with the Parameter -R:

# Example script to delete snapshots within `.system`
SYSTEM_DATASET=$(zfs list -H -o name | grep -m 1 '.system')
zfs list -t snapshot -r "$SYSTEM_DATASET" | awk '{print $1}' | while read SNAP; do
    echo "Destroying snapshot: $SNAP"
    zfs destroy "$SNAP" -R
done

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.