From 66a463edd6deecebc3db3bca34e7cfe20e65038c Mon Sep 17 00:00:00 2001 From: Alex Denes Date: Wed, 15 Jan 2025 12:21:07 +0000 Subject: [PATCH] Move prev deletion below and guarantee data flush before marking backup as finished --- btrfs/subvolume-delta-file | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/btrfs/subvolume-delta-file b/btrfs/subvolume-delta-file index 0d16742..65645df 100755 --- a/btrfs/subvolume-delta-file +++ b/btrfs/subvolume-delta-file @@ -2,6 +2,9 @@ # # BTRFS delta snapshots with incomplete send handling # CC0 ~caskd +# +# Note that this script currently has no locking mechanism +# This is left as a requirement to be guaranteed from the outside : ${SRC:?'Source not defined'} : ${SNAPDIR:?'Snapdir not defined'} @@ -37,6 +40,7 @@ delta() { [ -e "$DESTPATH.tmp" ] && rm -v "$DESTPATH.tmp" if btrfs -v send --compressed-data -p "$CUR" "$TMP" | compress > "$DESTPATH.tmp"; then + sync "$DESTPATH.tmp" mv -v "$DESTPATH.tmp" "$DESTPATH" ln -sv "../$TS_PARENT" "$DEST/$TS_CURRENT/$PARENTNAME" fi @@ -51,6 +55,7 @@ full() { [ -e "$DESTPATH.tmp" ] && rm -v "$DESTPATH.tmp" if btrfs -v send --compressed-data "$TMP" | compress > "$DESTPATH.tmp"; then + sync "$DESTPATH.tmp" mv -v "$DESTPATH.tmp" "$DESTPATH" fi } @@ -65,14 +70,13 @@ symdel() { mkdir -vp "$SNAPPATH" >&2 symdel "$TMP" -symdel "$PREV" - ln -sv "$CDATE" "$TMP" >&2 btrfs subvolume snapshot -r "$SNAPSRC" "$SNAPDEST" >&2 delta || full || return 1 # Mark snapshot transmission as complete +symdel "$PREV" [ -L "$CUR" ] && \ mv -v "$CUR" "$PREV" >&2 mv -v "$TMP" "$CUR" >&2