-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile-backup
executable file
·60 lines (51 loc) · 1.06 KB
/
file-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
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env bash
usage() {
echo -n " Usage: file-backup [OPTIONS]
Note: Requires root privileges to run
OPTIONS:
-s Source directories (space-separated)
-d Destination directory
DEFAULTS:
-s .config Documents Games Music Picturse Videos
-d /mnt
EXAMPLE:
# Backup directories .config and Documents to /tmp
file-backup -s \".config Documents\" -d /tmp
"
}
srcs=(.config Documents Games Music Pictures Videos)
dest=/mnt
home=/home/japorized
filterfile=$home/dotfiles/install/rsync-filter.txt
while getopts "d:s:h" opt; do
case "$opt" in
s)
srcs=(${OPTARG})
;;
d)
dest=${OPTARG}
;;
h)
usage
exit 0
;;
\?)
usage
exit 1
;;
esac
done
shift $((OPTIND -1))
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
fi
_rsync() {
sudo rsync --archive --human-readable --progress \
--filter=". ${filterfile}" "$@"
}
echo "=== Beginning backup ==="
for src in ${srcs[@]}; do
echo " ~~~ Backing up from $home/$src to $dest ~~~"
_rsync $home/$src $dest
done