forked from byxorna/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrsync_backup_simple
48 lines (35 loc) · 1.13 KB
/
rsync_backup_simple
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
#!/bin/bash
# written Jul 20 2009
###########################
#
# backup hosting1.wustl to /backup/hosting1
#
############################
DATE=`date +%Y-%m-%d-%R`
backup_host=hosting1
backup_domain=.wustl.edu
rsync_command="/usr/bin/rsync -avzR --delete"
failed=0
i=0 # counter for dirs to be backed up
backup_dirs=( \
/ \
)
for dir in ${backup_dirs[@]}
do
$rsync_command -e 'ssh -l root -c blowfish' $backup_host$backup_domain:$dir /backup/$backup_host/ > /dev/null 2>>/tmp/$backup_host-$DATE
errorcode[$i]=$? # set error code for this rsync
let i=i+1 # increment index
done
for code in ${errorcode[@]}
do
if [[ $code -ne 0 ]] ; then
echo "Error $code encountered by rsync for $backup_host" >>/tmp/$backup_host-$DATE
failed=1
fi
done
if [[ $failed -eq 0 ]] ; then # no errors, email success
subject="Backup complete for $backup_host [skillet.nts]"
else
subject="FAILED Backup report for $backup_host [skillet.nts]"
fi
/usr/bin/mail -s "$subject" [email protected] < "/tmp/$backup_host-$DATE"