Compare commits

...

1 Commits

Author SHA1 Message Date
07c189e962 Add zfs-auto-snapshot.sh script 2025-12-08 16:14:46 +01:00

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