-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbkup-home
executable file
·68 lines (61 loc) · 1.29 KB
/
bkup-home
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
#
# file: bkup-home
# author: Brian Buccola <[email protected]>
#
# description: This script creates a mirror image of $HOME on an external
# drive, excluding any files and directories in $EXCL.
src=$HOME
dest=/mnt/floyd
bkupdir=$HOME/.bkup-home
excl=$bkupdir/exclude-list
log=$bkupdir/log
script=$(basename $0)
usage() {
cat <<EOF
usage: $script [option]
options:
-n, --dryrun Do dryrun and pipe output to file instead of stdout
-h, --help Show this usage page
EOF
}
drive_test() {
if ! grep -qs "$dest " /proc/mounts; then
echo "Error: Drive not mounted!"
exit 0
fi
}
bkup() {
drive_test
rsync \
-avuhhh \
--exclude-from=$excl \
--delete \
--delete-excluded \
--log-file=$log \
--stats \
$src $dest
}
bkup_dryrun() {
drive_test
echo "Doing dryrun and piping output to $bkupdir/dryrun ..."
rsync \
-avnuhhh \
--exclude-from=$excl \
--delete \
--delete-excluded \
--stats \
$src $dest > $bkupdir/dryrun
echo "Done."
}
if [[ $# -eq 0 ]]; then
bkup
exit 0
elif [[ $# -eq 1 ]]; then
case $1 in
-n|--dryrun) bkup_dryrun && exit 0 ;;
*) usage && exit 0 ;;
esac
else
usage && exit 0
fi