scripts/misc-scripts/btrfs-retention.sh

19 lines
458 B
Bash
Raw Permalink Normal View History

2023-08-31 17:55:25 +00:00
#!/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
2023-08-31 17:55:25 +00:00
btrfs subvolume delete "$d"
btrfs subvolume snapshot -r "$s" "$d"