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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
|
#! /bin/csh -f
set tmpfile=/tmp/butmpf.$$
if (! $?BACKUP_HOME) then
set pnam=$0
set pnam = $pnam:t
if ($pnam == $0) then
foreach dir ($path)
if (-x $dir/$0) then
set p=$dir/$0
break
endif
end
if ($p == ./$pnam) then
set p=`pwd`
setenv BACKUP_HOME $p:h
else
set p=$p:h
setenv BACKUP_HOME $p:h
endif
else
if (./$pnam == $0) then
set p=`pwd`/$pnam
else
if (`echo $0|cut -c1` != "/") then
set p=`pwd`/$0
else
set p=$0
endif
endif
set p=$p:h
setenv BACKUP_HOME $p:h
endif
endif
set path=($BACKUP_HOME/bin $path)
rehash
unsetenv AWK
# the solaris awk is doin' dawn f...... BS
foreach awk (nawk gawk awk)
foreach dir ($path)
if (-x $dir/$awk) then
setenv AWK $dir/$awk
break
endif
end
if ($?AWK) break
end
if (! $?AWK) then
echo 'No awk ? Is this really a lovely UNIX ?'
echo 'Sorry. I have to exit.'
exit 1
endif
set configfile=$BACKUP_HOME/lib/backup.conf
alias getparam $AWK' '"'"'/^[ ]*'"'"'\!:1'"'"'/{split($0,a,"'"'"'\!:1'"'"'[ ]*"); print a[2]}'"' $configfile"
set host="`getparam 'BackupHost:?'`"
set rootdir="`getparam 'RootDirectory:?'`"
set dirstobackup="`getparam 'DirsToBackup:?'`"
set filestoskip="`getparam 'FilesToSkip:?'`"
set dirstoskip="`getparam 'DirsToSkip:?'`"
set indexfilepart="`getparam 'IndexFilePart:?'`"
set numindexestostore="`getparam 'NumIndexesToStore:?'`"
set compresscmd="`getparam 'CompressCmd:?'`"
set uncompresscmd="`getparam 'UncompressCmd:?'`"
set logfile="`getparam 'LoggingFile:?'`"
set numparts="`getparam 'NumBackupParts:?'`"
set startupinfoprog="`getparam 'StartupInfoProgram:?'`"
set compresslogfiles="`getparam 'CompressLogfiles:?'`"
if ("$compresslogfiles" != "0" && $compresslogfiles != "1") then
set compresslogfiles=0
endif
if ($numparts == "") set numparts=1
if ($numparts > 1) then
if ($numindexestostore < 1) set numindexestostore=1
if (-r $BACKUP_HOME/var/part) then
set part=`cat $BACKUP_HOME/var/part`
else
set part=0
endif
if (`echo $part|grep '^[0-9][0-9]*$'|wc -l` < 1) set part=0
@ part++
if ($part > $numparts) set part=1
set nam="DirsToBackup"$part
set dirstobackup="`getparam '${nam}:?'`"
else
set part=1
endif
if ("$compresscmd" != "" && "$uncompresscmd" != "") then
set compressoption=-z
else
set compresscmd="-v"
set uncompresscmd="-v"
set compressoption="-v"
endif
if ("$logfile" == "") then
set logfile=$BACKUP_HOME/var/backup.log
endif
touch $logfile
if ($numparts > 1) then
echo `date`: starting full backup part $part >> $logfile
else
echo `date`: starting full backup >> $logfile
endif
unalias cd
cd $rootdir
set dirstobackup=($dirstobackup)
if ( -r $BACKUP_HOME/var/num ) then
set num=`cat $BACKUP_HOME/var/num`
else
set num=0
endif
if (`echo $num|grep '^[0-9][0-9]*$'|wc -l` < 1) then
set num=0 # num doesn't contain a number
set part=1
endif
if ($part == 1) then
@ num++
echo $num >! $BACKUP_HOME/var/num
if (-e $BACKUP_HOME/var/oldmark) then
mv $BACKUP_HOME/var/oldmark $BACKUP_HOME/var/oldmark.org
endif
touch $BACKUP_HOME/var/oldmark
\rm -f "$indexfilepart"$num
endif
# if the logfile is compressed, uncompress it
if (-e "$indexfilepart"$num".z" && ! -e "$indexfilepart"$num) then
if ("$uncompresscmd" == "") then
set uncompresscmd=gunzip # assume gunzip can unzip anything
endif
set ok=0
foreach tmplogf ("$indexfilepart"$num /tmp/`basename "$indexfilepart"$num` \
/var/tmp/`basename "$indexfilepart"$num`)
cat "$indexfilepart"$num".z" | $uncompresscmd >! $tmplogf
if ($status == 0) then
set ok=1
break
endif
\rm -f $tmplogf
end
if ($ok) then
if ($tmplogf != "$indexfilepart"$num) then
cp $tmplogf "$indexfilepart"$num
\rm -f $tmplogf
endif
\rm -f "$indexfilepart"$num".z"
else
echo Warning: filename logging file cannot be uncompressed.
endif
endif
touch "$indexfilepart"$num
onintr emexit
# get startup information
if ("$startupinfoprog" != "") then
backup -Q -h $host >! $tmpfile
(echo 'Backup: '$num ; \
grep -i cartridge $tmpfile; grep -i file $tmpfile) | \
awk '{printf "~~%s\n",$0}' | sh -c "$startupinfoprog"
\rm -f $tmpfile
endif
# because the C-shell is so stupid we have to produce a find
# command script
set findcmd=/tmp/bufindcmd.$$
\rm -f $findcmd
echo "#! /bin/sh" >! $findcmd
echo -n exec find $dirstobackup >> $findcmd
if ($#dirstoskip > 0) then
echo $dirstoskip | \
awk 'BEGIN{printf " \\("}{for(i=1;i<=NF;i++) \
{ printf " -name \"%s\" ",$i; if (i<NF) printf "-o"}} \
END{printf "\\) -prune -o "}' >> $findcmd
endif
echo "$filestoskip" | \
awk '{for(i=1;i<=NF;i++) printf " ! -name \"%s\"",$i}' \
>> $findcmd
echo " -print" >> $findcmd
chmod +x $findcmd
# list all names, substitute \ by \\ and " by \" (the program backup
# needs this), put the whole thing into hyphens, pipe it into backup
$findcmd \
| sed 's/\\/\\\\/g;s/\"/\\\"/g' \
| awk '{printf "\"%s\"\n", $0}' \
| backup -cvn $compressoption "$compresscmd" "$uncompresscmd" \
-h $host >>& "$indexfilepart"$num
set bus=$status
# compress the logfile, if requested
if ($compresslogfiles && "$compresscmd" != "" && "$uncompresscmd" != "") then
set ok=0
foreach tmplf ("$indexfilepart"$num".z" \
/tmp/`basename "$indexfilepart"$num".z"`\
/var/tmp/`basename "$indexfilepart"$num".z"`)
cat "$indexfilepart"$num | $compresscmd >! $tmplf
if ($status == 0) then
set ok=1
break
endif
\rm -f $tmplf
end
if ($ok) then
if ($tmplf != "$indexfilepart"$num".z") then
cp $tmplf "$indexfilepart"$num".z"
\rm -f $tmplf
endif
\rm -f "$indexfilepart"$num
endif
endif
if ($bus != 0) then
echo `date`: full backup failed. >>$logfile
goto failexit
endif
if ("$numindexestostore" != "") then
@ num -=$numindexestostore
@ num--
while ($num > 0)
if (-e "$indexfilepart"$num || -e "$indexfilepart"$num".z") then
\rm -f "$indexfilepart"$num "$indexfilepart"$num".z"
else
break
endif
@ num--;
end
endif
if (-e $BACKUP_HOME/var/oldmark.org) then
\rm -f $BACKUP_HOME/var/oldmark.org
endif
if ($numparts > 1) then
echo $part >! $BACKUP_HOME/var/part
echo `date`: full backup part $part finished >> $logfile
else
echo `date`: full backup finished >> $logfile
endif
\rm -f $findcmd $tmpfile
exit 0
emexit:
echo `date`: full backup interrupted >> $logfile
failexit:
if (-e $BACKUP_HOME/var/oldmark.org) then
\mv -f $BACKUP_HOME/var/oldmark.org $BACKUP_HOME/var/oldmark
endif
\rm -f $findcmd $tmpfile
exit 1
|