-
Notifications
You must be signed in to change notification settings - Fork 584
/
056-backup.sh
executable file
·62 lines (51 loc) · 1.62 KB
/
056-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
#!/bin/sh
# Backup - create either a full or incremental backup of a set of
# defined directories on the system. By default, the output
# file is saved in /tmp with a timestamped filename, compressed.
# Otherwise, specify an output device (another disk, a removable).
usageQuit()
{
cat << "EOF" >&2
Usage: $0 [-o output] [-i|-f] [-n]
-o lets you specify an alternative backup file/device
-i is an incremental or -f is a full backup, and -n prevents
updating the timestamp if an incremental backup is done.
EOF
exit 1
}
compress="bzip2" # change for your favorite compression app
inclist="/tmp/backup.inclist.$(date +%d%m%y)"
output="/tmp/backup.$(date +%d%m%y).bz2"
tsfile="$HOME/.backup.timestamp"
btype="incremental" # default to an incremental backup
noinc=0 # and an update of the timestamp
trap "/bin/rm -f $inclist" EXIT
while getopts "o:ifn" opt; do
case "$arg" in
o ) output="$OPTARG"; ;;
i ) btype="incremental"; ;;
f ) btype="full"; ;;
n ) noinc=1; ;;
? ) usageQuit ;;
esac
done
shift $(( $OPTIND - 1 ))
echo "Doing $btype backup, saving output to $output"
timestamp="$(date +'%m%d%I%M')"
if [ "$btype" = "incremental" ] ; then
if [ ! -f $tsfile ] ; then
echo "Error: can't do an incremental backup: no timestamp file" >&2
exit 1
fi
find $HOME -depth -type f -newer $tsfile -user ${USER:-LOGNAME} | \
pax -w -x tar | $compress > $output
failure="$?"
else
find $HOME -depth -type f -user ${USER:-LOGNAME} | \
pax -w -x tar | $compress > $output
failure="$?"
fi
if [ "$noinc" = "0" -a "$failure" = "0" ] ; then
touch -t $timestamp $tsfile
fi
exit 0