-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathzfs-rclone-backup
49 lines (44 loc) · 2.89 KB
/
zfs-rclone-backup
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
46
47
48
49
#!/bin/bash
volume=$3
server=$1
pool=$2
frequency=$4
if [ $frequency == "daily" ]; then
lastsnap=$(zfs list $pool/$volume -t snapshot -o name -s creation -H 2>/dev/null | xargs zfs holds -H 2>/dev/null | grep backup-rclone | awk '{printf "%s\n",$1}' | tail -n 1)
if [ -z $lastsnap ]; then
echo "Could not find a recent snapshot with backup-rclone hold"
exit 55
fi
elif [ $frequency == "monthly" ]; then
lastsnap=$(zfs list $pool/$volume -t snapshot -o name -s creation -H 2>/dev/null | xargs zfs holds -H 2>/dev/null | grep -E "backup-rclone-(monthly|yearly)" | awk '{printf "%s\n",$1}' | tail -n 1)
if [ -z $lastsnap ]; then
echo "Could not find a recent snapshot with backup-rclone hold"
exit 55
fi
elif [ $frequency == "yearly" ]; then
lastsnap=$(zfs list $pool/$volume -t snapshot -o name -s creation -H 2>/dev/null | xargs zfs holds -H 2>/dev/null | grep backup-rclone-$frequency | awk '{printf "%s\n",$1}' | tail -n 1)
fi
newsnap=$(zfs list -t snapshot $pool/$volume -o name -s creation -H | tail -n1)
zfs hold backup-rclone-$frequency $newsnap
if [ $frequency == "yearly" ]; then
nice zfs send -c -w -v $newsnap 2>/root/zfssend-$volume.log | nice rclone --low-level-retries 99999 --retries-sleep 30m --config=/etc/rclone.conf --log-file=/root/rclonezfs-$volume.log rcat server-backup-crypt:zfs/$server/$newsnap-$frequency
else
nice zfs send -c -w -v -i $lastsnap $newsnap 2>/root/zfssend-$volume.log | nice rclone --low-level-retries 99999 --retries-sleep 30m --config=/etc/rclone.conf --log-file=/root/rclonezfs-$volume.log rcat server-backup-crypt:zfs/$server/$newsnap-$frequency
fi
if [ $? == 0 ]; then
if [ $frequency == "yearly" ]; then
if [ $lastsnap ]; then
zfs list $pool/$volume -t snapshot -o name -s creation -H 2>/dev/null | xargs zfs holds -H 2>/dev/null | grep backup-rclone-monthly | awk '{printf "%s\n",$1}' | xargs zfs release backup-rclone-monthly
zfs list $pool/$volume -t snapshot -o name -s creation -H 2>/dev/null | xargs zfs holds -H 2>/dev/null | grep backup-rclone-daily | awk '{printf "%s\n",$1}' | xargs zfs release backup-rclone-daily
zfs list $pool/$volume -t snapshot -o name -s creation -H 2>/dev/null | xargs zfs holds -H 2>/dev/null | grep backup-rclone-yearly | sed -e '${d;}' | awk '{printf "%s\n",$1}' | xargs zfs release backup-rclone-yearly
fi
elif [ $frequency == "monthly" ]; then
zfs holds -H $lastsnap | grep -v "backup-rclone-daily" | awk '{printf "%s\n",$2}' | xargs -i zfs release "{}" $lastsnap
elif [ $frequency == "daily" ]; then
zfs list $pool/$volume -t snapshot -o name -s creation -H 2>/dev/null | xargs zfs holds -H 2>/dev/null | grep backup-rclone-daily | sed -e '${d;}' | awk '{printf "%s\n",$1}' | xargs zfs release backup-rclone-daily
fi
else
zfs release backup-rclone-$frequency $newsnap
echo "Error sending dataset"
exit 69
fi