-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-backups-parallel.sh
executable file
·53 lines (42 loc) · 1.32 KB
/
create-backups-parallel.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
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
# Usage: create-backups-parallel.sh <parent-dataset> <backups-dir>
create_backup()
{
snapshot=$(/usr/sbin/zfs list -t snapshot -o name -s creation -r $1 | tail -1)
fstype=$(/usr/sbin/zfs get -H -o value type $1)
case $fstype in
volume)
echo "Backing up '$snapshot' to '$2.zfs.gz'"
/usr/sbin/zfs send $snapshot | gzip -c --best > $2.zfs.gz
;;
filesystem)
echo "Backing up '$snapshot' to '$2.tar.gz'"
snapshotdir="/mnt/${snapshot//@/\/.zfs\/snapshot\/}"
tar -I"gzip --best" -cf $2.tar.gz -C $snapshotdir .
;;
*)
echo "WARNING! Unsupporting file system type '$fstype'. Skipping $1"
;;
esac
echo "Backup of $1 complete"
}
echo "Queuing $1 backups..."
dirname=${1%*/}
dirname=${dirname##*/}
mkdir -p $2/$dirname
readarray -t excluded < $2/$dirname/exclude.txt
for vol in $(/usr/sbin/zfs list -o name -d 1 -Hr $1 | sed -n '1!p')
do
name=${vol%*/}
name=${name##*/}
if [[ " ${excluded[*]} " =~ " ${name} " ]]; then
echo "Skipping backup for excluded $vol"
else
echo "Queueing backup for $vol"
create_backup $vol $2/$dirname/$name &
fi
done
# Wait for all backups to complete
echo "Waiting for all backups to complete..."
wait
echo "Backups complete"