-
Notifications
You must be signed in to change notification settings - Fork 0
/
76a-remotebackup
48 lines (38 loc) · 1.37 KB
/
76a-remotebackup
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
#!/bin/bash
# remotebackup - Takes a list of files and directories,
# builds a single compressed archive, then emails it off to a
# remote archive site for safekeeping. It's intended to be run
# every night for critical user files, but not intended to
# replace a more rigorous backup scheme. You should strongly
# consider using unpacker, Script #77, on the remote end too.
outfile="/tmp/rb.$$.tgz"
outfname="backup.$(date +%y%m%d).tgz"
infile="/tmp/rb.$$.in"
trap "`which rm` -f $outfile $infile" 0
if [ $# -ne 2 -a $# -ne 3 ] ; then
echo "Usage: $(basename $0) backup-file-list remoteaddr {targetdir}" >&2
exit 1
fi
if [ ! -s "$1" ] ; then
echo "Error: backup list $1 is empty or missing" >&2
exit 1
fi
# Scan entries and build fixed infile list. This expands wildcards
# and escapes spaces in filenames with a backslash, producing a
# change: "this file" becomes this\ file so quotes are not needed.
while read entry; do
echo "$entry" | sed -e 's/ /\\ /g' >> $infile
done < "$1"
# The actual work of building the archive, encoding it, and sending it
tar czf - $(cat $infile) | \
uuencode $outfname | \
mail -s "${3:-Backup archive for $(date)}" "$2"
echo "Done. $(basename $0) backed up the following files:"
sed 's/^/ /' $infile
echo -n "and mailed them to $2 "
if [ ! -z "$3" ] ; then
echo "with requested target directory $3"
else
echo ""
fi
exit 0