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