summaryrefslogtreecommitdiff
path: root/bin/byo
blob: bc09fb80d4b44f132f40ffe9917967fc7e08ff12 (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
#!/bin/sh -e
# Backup to yoda
[ "$USER" = root ] || exec sudo "$0" "$@"

usage='Usage: byo [-cdk] [/dev/sda2]
Backup local disk to yoda external disk.

Options:
  -c  close and umount yoda
  -d  dedupe yoda
  -k  do not umount and close yoda
'

while getopts :Ccdk opt; do
	case $opt in
	(C|c|d|k) eval "opt$opt=$opt" ;;
	(*) printf %s "$usage"; exit 1 ;;
	esac
done
shift $((OPTIND - 1))

dev=$1
yoda_uuid='8c463221-6bb7-414e-9060-c9570bb3a6bb'
[ "$dev" ] || dev=$(blkid --uuid "$yoda_uuid")

dest=/mnt/backup/$(hostname)
[ -b /dev/mapper/yoda ] && noclose=1 || cryptsetup open "$dev" yoda
findmnt /dev/mapper/yoda /mnt >/dev/null && noumount=1 || mount /dev/mapper/yoda /mnt
time backup -v -d "$dest"
[ ! "$optC" ] || backup -v -d "$dest" clean
[ ! "$optd" ] || time duperemove -drh --hashfile="$dest/.hashfile" "$dest"
df -h / "$dest"
ls -v "$dest"
[ ! "$optk" ] || noumount=1 noclose=1
[ ! "$optc" ] || noumount='' noclose=''
[ "$noumount" ] || umount /mnt
[ "$noclose" ] || cryptsetup close yoda
echo "bye"