summaryrefslogtreecommitdiff
path: root/src/btrfs-send-root.sh
blob: 8a3a51312aeca584be595de159ef0c181b06d260 (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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/sh
. samizdat-paths.sh
. var.sh
. btrfs-functions.sh

rootfs_uuid ()
{
    btrfs filesystem show / | sed -ne 's/.*uuid: //p'
}

remote_btrfs_receiver()
{
#   ssh "$BTRFS_RECEIVE_DESTINATION_HOST" -- "sudo btrfs receive $(shellescape "$BTRFS_RECEIVE_DESTINATION_PATH")"
    ssh "$BTRFS_RECEIVE_DESTINATION_HOST" -- \
        "sudo sh sami/btrfs-receive-root.sh $(shellescape "$BTRFS_RECEIVE_DESTINATION_PATH") $(shellescape "$BTRFS_RECEIVE_SUBVOLUME_NAME")"
}

dummy_receiver()
{
    true
}

push_remote()
{
    $(ARGS_NE mnt src ssh_dst)

    now=$(date +%F.%H%M%S) || die
    snap_dir=$mnt/snapshot.$now
    prev_dir=$mnt/SEED

    case "$ssh_dst" in
        *:*) ;;
        *) return 1;;
    esac
    local BTRFS_RECEIVE_DESTINATION_PATH="${ssh_dst#*:}"
    local BTRFS_RECEIVE_DESTINATION_HOST="${ssh_dst%%:*}"
    local BTRFS_RECEIVE_SUBVOLUME_NAME="${snap_dir#$mnt/}"
    push_helper false "$snap_dir" "$prev_dir" "$src" remote_btrfs_receiver
}

ssh_dst=d@fifty.local:sami/test_dest

mkdir -p /mnt/rootfs || die
mountpoint -q /mnt/rootfs || mount -o subvol=/ UUID=$(rootfs_uuid) /mnt/rootfs || die
push_remote /mnt/rootfs / "$ssh_dst"