#!/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. setglobal outfile = ""/tmp/rb.$Pid.tgz"" setglobal outfname = ""backup.$[date +%y%m%d].tgz"" setglobal infile = ""/tmp/rb.$Pid.in"" trap "$[which rm] -f $outfile $infile" 0 if test $Argc -ne 2 -a $Argc -ne 3 { echo "Usage: $[basename $0] backup-file-list remoteaddr {targetdir}" > !2 exit 1 } if test ! -s $1 { echo "Error: backup list $1 is empty or missing" > !2 exit 1 } # 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 { echo $entry | sed -e 's/ /\\ /g' >> $infile } < "$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 test ! -z $3 { echo "with requested target directory $3" } else { echo "" } exit 0