-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbackup-home
More file actions
executable file
·49 lines (39 loc) · 831 Bytes
/
backup-home
File metadata and controls
executable file
·49 lines (39 loc) · 831 Bytes
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
#!/bin/sh
usage()
{
cat >&2 <<__EOF__
Usage: $(basename $0) <backup-dir>
Options:
backup-dir -- Name of the backup directory, e.g. /mnt/laptop.
__EOF__
exit ${1-1}
}
log()
{
echo "$(basename $0): $1" >&2
}
export PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin
trap 'rm -f $EXCLUDES; exit 0' SIGINT SIGHUP SIGTERM EXIT
if [ $# -ne 1 ]; then
usage
fi
DSTDIR="$1"
if [ ! -d "$DSTDIR" ]; then
log "backup-dir must be an existing directory. Exiting."
exit 1
fi
EXCLUDES=$(mktemp -t $(basename $0))
if [ -z "$EXCLUDES" ]; then
log "Failed to create temporary file. Exiting."
exit 1
fi
cat <<__EOF__ > $EXCLUDES
dl
mnt
src/*-obj/
src/freebsd-ports/distfiles/*
tmp
var
vbox
__EOF__
rsync -akv --safe-links --exclude-from=$EXCLUDES $HOME/* "$DSTDIR"/${USER}-$(hostname -s)