Skip to content

Instantly share code, notes, and snippets.

@ReSearchITEng
Last active March 22, 2024 13:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ReSearchITEng/48f5722bfddfca09ed5c782337de5299 to your computer and use it in GitHub Desktop.
Save ReSearchITEng/48f5722bfddfca09ed5c782337de5299 to your computer and use it in GitHub Desktop.
clean zfs snapshots

ubuntu clean zfs snapshots

1. cleanup using docker

docker system prune -a -f --volumes

2. clean everything else

by using tool:

https://github.com/bahamas10/zfs-prune-snapshots

echo "dry run for 1 week:"
zfs-prune-snapshots -R -n 1w
read
echo "actual execution:"
sudo zfs-prune-snapshots -R 1w

or manually everything

zpool list
for s in $(zfs list -t snapshot | grep rpool | grep containerd | cut -d' ' -f1 ); do echo $s; zfs destroy -R $s; done
for s in $(zfs list -t snapshot | grep rpool | grep docker | cut -d' ' -f1 ); do echo $s; zfs destroy -R $s; done
for s in $(zfs list -t snapshot | grep rpool | grep USERDATA | cut -d' ' -f1 ); do echo $s; zfs destroy -R $s; done
for s in $(zfs list -t snapshot | grep rpool | grep ROOT | cut -d' ' -f1 ); do echo $s; zfs destroy -R $s; done
zpool list

3. restart zfs services

sudo systemctl restart zsysd.service
sudo systemctl restart zsys-gc
sudo systemctl status zsysd.service
sudo systemctl status zsys-gc

4. verify

zsysctl show
zsysctl list
zfs list -t snapshot | wc -l
zfs list | wc -l
source <(zsysctl completion bash)
# Linux:
zsysctl completion bash > /etc/bash_completion.d/zsysctl
zfs completion bash > /etc/bash_completion.d/zfs

5. config review

sudo find /etc -name "*zsys*"
sudo vi /etc/zsys.conf # https://github.com/ubuntu/zsys/blob/master/internal/config/zsys.conf
sudo zsysctl service reload # to reload config

Uselful links

  1. ubuntu/zsys#193
  2. https://kimono-koans.github.io/opinionated-guide/ (includes info on nice tools: sanoid and syncoid )
  3. https://didrocks.fr/2020/06/04/zfs-focus-on-ubuntu-20.04-lts-zsys-state-collection/
  4. https://github.com/bahamas10/zfs-prune-snapshots
  5. https://github.com/ubuntu/zsys/blob/master/internal/config/zsys.conf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment