scripts/misc-scripts/btrfs-retention.sh

19 lines
458 B
Bash
Executable File

#!/bin/sh
#
# BTRFS rolling snapshots
# CC0 ~caskd
: ${SRC:?'Source not defined'}
: ${DEST:?'Destination not defined'}
: ${NAME:?'Name not defined'}
: ${SN:?'Selection name not defined'}
: ${RT:?'Retention time not defined'}
s="$SRC"
d="$DEST/$SN/$NAME"
mkdir -p "${d%/*}"
find "$DEST" -mindepth 1 -maxdepth 1 -type d -ctime +"$RT" -exec echo "{}/$NAME" ';' | xargs -r btrfs subvolume del
btrfs subvolume delete "$d"
btrfs subvolume snapshot -r "$s" "$d"