Add zfs-auto-snapshot.sh script

This commit is contained in:
2025-12-08 16:14:46 +01:00
parent dceb17cd57
commit a5056198ab
2 changed files with 30 additions and 0 deletions

View File

@@ -6,3 +6,4 @@ Some helpful bash scripts for [incus](https://linuxcontainers.org/incus)
- incus-backup: Backup instances FS and DBs to a remote location using rsync over ssh.
- incus-copy: Run a differential copy of all running instances to a remote incus server.
- incus-snapshot: Take a snapshot on all running instances.
- zfs-auto-snapshot: Create and cleanup expired zfs snapshots.

29
zfs-auto-snapshot.sh Executable file
View File

@@ -0,0 +1,29 @@
#!/bin/bash
#
# Create zfs snapshots for $DATASET
# https://github.com/bahamas10/zfs-prune-snapshots
#
#set -x
while getopts d:e: flag
do
case "${flag}" in
d) DATASET=${OPTARG};;
e) EXPIRATION=${OPTARG};;
esac
done
DATE=$(date '+%Y-%m-%d %H:%M:%S')
TS=$(date '+%s')
ZFS=$(which zfs)
CMD="$ZFS snapshot ${DATASET}@snap${TS}"
echo "[${DATE}] $CMD"
$CMD 2>&1 > /dev/null
ZFS_PRUNE_SNAPSHOTS=$(which zfs-prune-snapshots)
CMD="$ZFS_PRUNE_SNAPSHOTS -p 'snap' $EXPIRATION $DATASET"
echo "[${DATE}] $CMD"
$CMD 2>&1 > /dev/null