-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackup-desktop
executable file
·50 lines (41 loc) · 1.37 KB
/
backup-desktop
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/bash
#
# Designed to be run daily. Make sure the "DROPBOX" is set up
# and running rsyncd in an appropriate way. This works on MacOS and
# probably other platforms with some tweaks.
#
# When running this on a mac, first grant Full Disk Access to:
# /usr/sbin/cron, /bin/bash, /usr/bin/rsync, Terminal.app, and this script.
#
set -f
RHOST=DROPBOX
EMAIL=NAME@EXAMPLE.com
PFX=/tmp/backup
LOG=$PFX.out
LOCK=$PFX.lock
# only one backup can run at a time
shlock -p $$ -f $LOCK || exit 0
HOST=`hostname -s | tr 'A-Z' 'a-z'`
RSYNC=/usr/bin/rsync
FLAGS="-v -r -l --copy-unsafe-links -p -o -g -t -S --delete-during --delete-excluded --max-delete=100 --ignore-errors"
date > $LOG
backdir() { # <srcpath> <dstpath> <flags>...
xSRC=$1/
xDST=${RHOST}::$2/
shift 2
xCMD="$RSYNC $FLAGS $* $xSRC $xDST"
echo $xCMD >> $LOG
$xCMD >> $LOG 2>&1
xRES=$?
if [ $xRES -ne 0 -a $xRES -ne 23 -a $xRES -ne 24 ]; then
echo Failed to back up ${HOST}:$xSRC $xRES \
| mail -s "BACKUP $HOST $xSRC" $EMAIL
fi
date >> $LOG
}
backdir $HOME backedup/$USER/${HOST}_home '--exclude=.Trash/ --exclude=/build/ --exclude=Caches/ --exclude=/Music/ --exclude=iTunes* --exclude=iPhoto*'
backdir $HOME/Music nobackup/$USER/${HOST}_music
backdir /Volumes/LargeDisk/$USER/Photos backedup/shared/${HOST}_photos
backdir /Volumes/LargeDisk/ameyer/Scans backedup/shared/${HOST}_scans
rm -f $LOCK
##### EOF #####