-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackup.sh
More file actions
50 lines (39 loc) · 1.35 KB
/
backup.sh
File metadata and controls
50 lines (39 loc) · 1.35 KB
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
#!/bin/sh
### Backup script
### 3rd Stone Consulting
### Last modified July 2016
### Requires rsync 3: https://rsync.samba.org/
# set rsync location
RSYNC_BIN="/usr/local/bin/rsync"
# set log archives location
LOG_DIR="/Library/Logs/backup-log-archive/"
# set name/format of time stamped log file
LOGNAME=rsync-`date +%Y-%m-%d-%T`.log
# define source directory
SOURCE_DIR="/Volumes/Storage/"
# define backup destination
BACKUP_DIR="/Volumes/Backup/"
# set exclude file location
EXCLUDE="/Library/Scripts/Backup/rsync_excludes.txt"
# set email notification address
EMAIL="admin@org.ca"
if [ ! -d "$LOG_DIR" ]; then
mkdir $LOG_DIR
fi
cp /Library/Logs/backup.log $LOG_DIR/$LOGNAME
rm -f /Library/Logs/backup.log && touch /Library/Logs/backup.log
#### Clean up backup logs ####
find $LOG_DIR -mtime +14 -exec rm {} \;
echo Backup started >> /Library/Logs/backup.log
date >> /Library/Logs/backup.log
cd $SOURCE_DIR
# begin backup
$RSYNC_BIN --dry-run -avNHXxh --fileflags --force-change --rsync-path="$RSYNC_BIN" \
--backup --backup-dir=../`date +%y:%m:%d` \
--delete-excluded --exclude-from=$EXCLUDE \
$SOURCE_DIR/ $BACKUP_DIR/ >> /Library/Logs/backup.log
#### Stamp the log and send the notification ####
echo Backup complete >> /Library/Logs/backup.log
date >> /Library/Logs/backup.log
# cat /Library/Logs/backup.log | mail -s "Client: Server - backup complete" $EMAIL
exit