local/bin/btrfs-backup: Add script for easy btrfs incremental backups.

master
Pierre Neidhardt 2019-08-26 15:02:10 +02:00
parent 5ade220869
commit 9229e86bbd
1 changed files with 39 additions and 0 deletions

39
.local/bin/btrfs-backup Executable file
View File

@ -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