fix(dblab,zfs): delete snapshots older than a threshold date

This commit is contained in:
Michele Cereda
2025-12-19 10:01:15 +01:00
parent b06830674b
commit e4b35e88c3
2 changed files with 36 additions and 0 deletions

View File

@@ -13,6 +13,7 @@ The [website] hosts the SaaS version.
1. [Launch DBLab server](#launch-dblab-server)
1. [Clean up](#clean-up)
1. [Automatically full refresh data without downtime](#automatically-full-refresh-data-without-downtime)
1. [Deleting snapshots](#deleting-snapshots)
1. [Troubleshooting](#troubleshooting)
1. [Cannot destroy automatic snapshot in the pool](#cannot-destroy-automatic-snapshot-in-the-pool)
1. [The automatic full refresh fails claiming it cannot find available pools](#the-automatic-full-refresh-fails-claiming-it-cannot-find-available-pools)
@@ -394,6 +395,31 @@ without downtime.
> Prefer dedicating an entire disk to each pool or logical volume.<br/>
> This avoids overloading a single disk when syncing, and prevents the whole data failing should a disk fail.
## Deleting snapshots
Prefer deleting snapshots via the server (CLI, API or UI).<br/>
In case that is not possible, consider using the `zfs` utility to delete them.
> [!caution]
> The engine will **not** notice snapshots deletion until the server is restarted.
```sh
# Delete all but the 4 most recent snapshots
zfs list -Hp -t 'snapshot' -S 'creation' -o 'name' \
| sed '1,4d' \
| xargs -n '1' zfs destroy -nv
# Delete all snapshots older than 31d (pre zfs-2.3)
zfs list -Hp -t 'snapshot' -o 'name,creation' | while read -r SNAPSHOT CREATION; do
if [[ $CREATION -ge $(date -d "31 days ago" +%s) ]]; then
echo "'$SNAPSHOT' is recent enough to be kept."
else
echo "'$SNAPSHOT' is old and is about to be deleted."
zfs destroy -nv "$SNAPSHOT"
fi
done
```
## Troubleshooting
### Cannot destroy automatic snapshot in the pool

View File

@@ -152,6 +152,16 @@ zfs destroy 'path/to/clone'
# Destroy datasets older than the most recent 4
zfs list -Hp -t 'snapshot' -S 'creation' -o 'name' | sed '1,4d' | xargs -n '1' -t zfs destroy -nv
# Destroy all snapshots older than 31d (pre zfs-2.3)
zfs list -Hp -t 'snapshot' -o 'name,creation' | while read -r SNAPSHOT CREATION; do
if [[ $CREATION -ge $(date -d "31 days ago" +%s) ]]; then
echo "'$SNAPSHOT' is recent enough to be kept."
else
echo "'$SNAPSHOT' is old and is about to be deleted."
zfs destroy -nv "$SNAPSHOT"
fi
done
# Query a file system or volume configuration (get properties).
zfs get 'all' 'pool_name'
zfs get 'aclmode,aclinherit,acltype,xattr' 'pool_name/filesystem_name'