-
Notifications
You must be signed in to change notification settings - Fork 1
/
nas_backup.sh
executable file
·72 lines (54 loc) · 1.63 KB
/
nas_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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env bash
#------------------------------------------------------------------------------
# Initial Date: 2016-09-04
#------------------------------------------------------------------------------
error() { echo "--error-- $@" 1>&2; exit -1; }
#------------------------------------------------------------------------------
USAGE="usage: $(basename $0) <filelist>"
DESTDIR=/share/USBDisk1/nas
DATE=$(date +%Y-%m-%d)
TIME=$(date +%H-%M-%S)
BACKUPDIR=$DESTDIR/_backup-logs/$DATE.$TIME
#------------------------------------------------------------------------------
main()
{
local filelist failfile src dest log msg i
if [ $# -ne 1 ]
then
error "usage: $(basename $0) <filelist>"
fi
filelist=$1
cd $DESTDIR
if [ "$(pwd)" != "$DESTDIR" ]
then
error "Must be run from $DESTDIR"
fi
mkdir -p $BACKUPDIR
failfile=$BACKUPDIR/FAILED
dirs=( $(cat $filelist) )
for (( i=0; i<${#dirs[@]}; i+=2 ))
do
src=${dirs[$i]}
dest=${dirs[$i+1]}
log=$BACKUPDIR/$(basename $dest).log
rsync --recursive \
--links \
--stats \
--times \
--omit-dir-times \
--itemize-changes \
--progress \
--human-readable \
--delete-before \
$src $dest 2>&1 | tee $log
if [ ${PIPESTATUS[0]} -ne 0 ]
then
msg="backup failed: $src $dest"
echo $dest >> $failfile
else
msg="$dest [ok]"
fi
echo $msg | tee -a $log
done
}
main "$@"