From f641a5445e74a3eb48da311dda9cf12118b39bf4 Mon Sep 17 00:00:00 2001 From: Alex Denes Date: Sat, 9 Nov 2024 20:19:38 +0000 Subject: [PATCH] Allow override of dstdir with subvolume delta and add snapshot with retention --- btrfs/btrfs-subvolume-delta | 2 +- btrfs/snapshot | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100755 btrfs/snapshot diff --git a/btrfs/btrfs-subvolume-delta b/btrfs/btrfs-subvolume-delta index 9b2b679..6d911bc 100755 --- a/btrfs/btrfs-subvolume-delta +++ b/btrfs/btrfs-subvolume-delta @@ -3,7 +3,7 @@ set -e SRC="$1" RECV="$2" -DSTDIR="$SRC/.snap" +DSTDIR="$SRC/${3:-.snap}" CDATE="$(date '+%s')" PREV="prev" CUR="cur" diff --git a/btrfs/snapshot b/btrfs/snapshot new file mode 100755 index 0000000..4a61e8e --- /dev/null +++ b/btrfs/snapshot @@ -0,0 +1,18 @@ +#!/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 btrfs subvolume del +btrfs subvolume delete "$d" +btrfs subvolume snapshot -r "$s" "$d"