aboutsummaryrefslogtreecommitdiff
path: root/btrfs_incremental_send
blob: 1d34c49678e2203edde58a4f7585b04d679bd306 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/bin/bash

# send all subvolumes incrementally from SOURCE to DEST

set -e

SOURCE="$1"
DEST="$2"

paste <(ls "$SOURCE" ) <(ls "$SOURCE" | sed 1d) | sed '$d' |
while read l; do
  PARENT=$(echo "$l" | cut -f1);
  VOLUME=$(echo "$l" | cut -f2);
  if [ ! -d "$DEST/$VOLUME" ]
  then
    if [ ! -d "$DEST/$PARENT" ]
    then
      echo "putative parent $DEST/$PARENT does not exist on destination!"
      exit 2
    fi
    echo "[($SOURCE/$PARENT) $SOURCE/$VOLUME => $DEST/$VOLUME]"
    sudo btrfs send -p "$SOURCE/$PARENT" "$SOURCE/$VOLUME" |
    pv | sudo btrfs receive "$DEST"
  fi
done