forked from Phantas0s/.dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup.sh
executable file
·56 lines (48 loc) · 1.46 KB
/
backup.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
54
55
56
#!/bin/zsh
dry_run=${dry_run:-false}
while getopts d: option
do
case "${option}"
in
d) dry_run=${OPTARG};;
esac
done
backup() {
local BACKUP="$MEDIA/BACKUP"
[ ! -d $BACKUP ] && echo "ABORT - The directory $MEDIA/BACKUP doesn't exist" && return
declare -A folders=(
# $MEDIA/test test-test/test
$HOME/Documents home/Documents
$HOME/Videos home/Videos
$HOME/Nextcloud home/nextcloud
$HOME/workspace home/workspace
$HOME/Games/scummvm home/Games/scummvm
$HOME/Games/internet home/Games/internet
$HOME/Games/dosbox home/Games/dosbox
$HOME/Games/emulators home/Games/emulators
$HOME/.local/share home/.local/share
$HOME/.thunderbird home/.thunderbird
$MEDIA/assets assets
$MEDIA/Documentaries documentaries
$MEDIA/Ebooks ebooks
$MEDIA/Install install
$MEDIA/MAO mao
$MEDIA/Music music
$MEDIA/Photos photos
$MEDIA/Video video
)
for key val in "${(@kv)folders}"; do
local src=$key
local dest="$BACKUP/$val"
[ ! -d $src ] && echo "The directory $key doesn't exist -- NO BACKUP CREATED" && continue
mkdir -p $dest
if [[ "$dry_run" != true ]]; then
rsync -avz --delete $src/ $dest 2>> "/tmp/backup_log"
else
rsync -avz --delete --dry-run $src/ $dest
fi
done
echo "ERRORS:\n\n"
cat "/tmp/backup_log"
}
backup