Initial commit with btrfs delta
This commit is contained in:
commit
bcd6f0f635
47
btrfs/btrfs-subvolume-delta
Executable file
47
btrfs/btrfs-subvolume-delta
Executable file
@ -0,0 +1,47 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
SRC="$1"
|
||||
RECV="$2"
|
||||
DSTDIR="$SRC/.snap"
|
||||
CDATE="$(date '+%s')"
|
||||
PREV="prev"
|
||||
CUR="cur"
|
||||
TMP="tmp"
|
||||
|
||||
msg() {
|
||||
echo "$1" >&2
|
||||
}
|
||||
|
||||
delta() {
|
||||
[ -d "$(realpath "$DSTDIR/$CUR")" ] || return 1
|
||||
msg "Attempting to send delta"
|
||||
btrfs -v send --compressed-data -p "$DSTDIR/$CUR" "$DSTDIR/$TMP" | btrfs -v receive "$RECV"
|
||||
}
|
||||
|
||||
full() {
|
||||
msg "Attempting to send full"
|
||||
btrfs -v send --compressed-data "$DSTDIR/$TMP" | btrfs -v receive "$RECV"
|
||||
}
|
||||
|
||||
symdel() {
|
||||
if [ -L "$1" ]; then
|
||||
btrfs subvolume delete "$1" >&2 || true
|
||||
rm -v "$1" >&2
|
||||
fi
|
||||
}
|
||||
|
||||
mkdir -vp "$DSTDIR" >&2
|
||||
|
||||
symdel "$DSTDIR/$TMP"
|
||||
symdel "$DSTDIR/$PREV"
|
||||
|
||||
ln -sv "$CDATE" "$DSTDIR"/"$TMP" >&2
|
||||
btrfs subvolume snapshot -r "$SRC" "$DSTDIR/$CDATE" >&2
|
||||
|
||||
delta || full
|
||||
|
||||
# Mark snapshot transmission as complete
|
||||
[ -L "$DSTDIR/$CUR" ] && \
|
||||
mv -v "$DSTDIR/$CUR" "$DSTDIR/$PREV" >&2
|
||||
mv -v "$DSTDIR/$TMP" "$DSTDIR/$CUR" >&2
|
Loading…
Reference in New Issue
Block a user