Move prev deletion below and guarantee data flush before marking backup as finished

This commit is contained in:
Alex D. 2025-01-15 12:21:07 +00:00
parent 2481728f4f
commit 66a463edd6
Signed by: caskd
GPG Key ID: F92BA85F61F4C173

View 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