Add zfs-auto-snapshot.sh script
This commit is contained in:
@@ -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-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-copy: Run a differential copy of all running instances to a remote incus server.
|
||||||
- incus-snapshot: Take a snapshot on all running instances.
|
- 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
29
zfs-auto-snapshot.sh
Executable 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
|
||||||
|
|
||||||
Reference in New Issue
Block a user