local/bin/btrfs-backup: Add script for easy btrfs incremental backups.
parent
5ade220869
commit
9229e86bbd
|
@ -0,0 +1,39 @@
|
|||
#!/bin/sh
|
||||
|
||||
usage () {
|
||||
cat <<EOF>&2
|
||||
Usage: ${0##*/} SOURCE TARGET
|
||||
|
||||
Synchronize all the snapshots in the SOURCE/.snapshots to TARGET/.snapshots.
|
||||
|
||||
EOF
|
||||
}
|
||||
|
||||
if [ $# -ne 2 ]; then
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
SOURCE="$1"
|
||||
TARGET="$2"
|
||||
|
||||
for i in "$SOURCE"/.snapshots/*; do
|
||||
if echo "$i" | grep -q 2019 ; then
|
||||
echo "TODO: Temporarily ignoring snapshot '$i' with dates directly in .snapshots."
|
||||
continue
|
||||
fi
|
||||
parent=""
|
||||
target_i="$TARGET/.snapshots/$(basename "$i")"
|
||||
for j in "$i"/*; do
|
||||
if [ ! -e "$target_i/$(basename "$j")" ]; then
|
||||
if [ -z "$parent" ] ; then
|
||||
sudo btrfs send "$j" | sudo btrfs receive "$target_i"
|
||||
else
|
||||
sudo btrfs send -p "$parent" "$j" | sudo btrfs receive "$target_i"
|
||||
fi
|
||||
fi
|
||||
parent="$j"
|
||||
done
|
||||
## Unset parent for next "i" subvolume.
|
||||
parent=""
|
||||
done
|
Loading…
Reference in New Issue