forked from hughobrien/zfs-remote-mirror
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackup.sh
executable file
·41 lines (33 loc) · 934 Bytes
/
backup.sh
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
#!/bin/sh
last_sent_file=~/.knox-last-sent
[ ! -f "$last_sent_file" ] && touch "$last_sent_file"
latest_remote="$(cat "$last_sent_file")"
[ -z $latest_remote ] && echo "remote state unknown. Set it in $last_sent_file"
latest_local="$(zfs list -H -d1 -t snapshot\
| grep -e '-[0-9][0-9]T[0-9][0-9]:' \
| cut -f1 \
| sort \
| tail -n 1)"
snapshot() {
zfs snapshot -r "wd@$(date -u '+%FT%TZ')"
}
send_incremental_snapshot() {
ssh knox-fifo < ~/.ssh/knox-geli-key &
sleep 3
zfs send -RevI "$latest_remote" "$latest_local" \
| ssh knox-send
}
preview() {
zfs diff "$latest_remote" "$latest_local" | less
echo "Size in MB:" $(echo $snapshot_size / 1024^2 | bc)
}
backup() {
send_incremental_snapshot && echo "$latest_remote" > "$last_sent_file"
}
case "$1" in
backup) backup ;;
preview) preview ;;
snapshot) snapshot ;;
snapback) snapshot; backup ;;
*) echo "Commands are: snapshot, backup, preview, snapback"
esac