#!/usr/local/bin/bash echo Starting backup at "`date`" if tty -s then ONTTY=true set -x else ONTTY=false fi PATH=/usr/local/bin:/usr/local/etc:$PATH export PATH case "`whoami`" in root) export HOME=~root ;; esac DESTDIR=/home/esmf.uci-esmf #DESTDIR=/notthere/gfs045/backup SRCDIR=/home export DESTDIR SRCDIR if [ "$ONTTY" = true ] then # apply a scaling factor for metadata overhead #approxsizeinkbytes="$(du -sk $SRCDIR | awk ' { print $1 }')" #approxsizeinkbytes="$(echo 'scale=0; ' $(du -sk . | awk ' { print $1 }') \* 1.1 \* 1024 | bc)" unadjusted="$(du -sk $SRCDIR | awk ' { print $1 }')" approxsizeinkbytes="$(echo $unadjusted \* 1.1 | bc | sed 's/\..*$//')" fi if ! Sinit then echo Initial Sinit failed 1>&2 exit 1 fi if ! Smkdir -p "$DESTDIR"/backups then echo "Smkdir -p $DESTDIR/backups" failed 1>&2 exit 1 fi Scd "$DESTDIR"/backups || \ { echo "$0: cd to" $DESTDIR/backups failed | mailx -s 'ESMF backup trouble' dcs@hydra.acs.uci.edu strombrg@dcs.nac.uci.edu touch /tmp/Backup-failed exit 1 } Smkdir -p daily.1 Smkdir -p daily.2 Smkdir -p weekly.1 Smkdir -p weekly.2 Smkdir -p monthly.1 Smkdir -p monthly.2 day_of_month="`date +%d`" day_of_week="`date +%a`" if ! Srm -rf daily.2 then echo Error cleaning up daily.2 1>&2 exit 1 fi if ! Smv daily.1 daily.2 then echo Error mving daily.1 to daily.2 1>&2 exit 1 fi if ! Smkdir -p daily.1 then echo Error mkdiring daily.1 1>&2 exit 1 fi if ! Scd daily.1 then echo Error cding up daily.1 1>&2 exit 1 fi if ! FULLPATH="$(Spwd)" then echo Erroring getting pwd 1>&2 exit 1 else export FULLPATH fi if ! (cd "$SRCDIR" && gtar cf - .) | \ if [ "$ONTTY" = true ] then # give a running tally of progress, with estimated time to # completion if [ 1 = 0 ] then reblock -e "$approxsizeinkbytes" $(expr 1024 \* 1024) 300 else reblock -f $(expr 1024 \* 1024) 300 fi else # only summarize throughput reblock -f $(expr 1024 \* 1024) 300 fi | \ mtee \ 'gtar tvf - | gzip | chunkup -b 268435456 -n tvf -c "Scpbase"' \ 'gzip | chunkup -b 268435456 -n archive -c "Scpbase"' \ "wc -c | sed 's/$/ total bytes transmitted/'" then echo Error writing archive and/or table of contents 1>&2 exit 1 fi if ! Scd .. then echo Error cding up a level 1>&2 exit 1 fi if [ "$day_of_week" = Sun ] then if ! Srm -rf weekly.2 then echo Error rming weekly.2 1>&2 exit 1 fi if ! Smv weekly.1 weekly.2 then echo Error mving weekly.1 to weekly.2weekly.1 to weekly.2 1>&2 exit 1 fi if ! Smkdir weekly.1 then echo Error mkdiring weekly.1 1>&2 exit 1 fi if ! Scp "daily.1/*" "weekly.1/." then echo Error copying daily.1 to weekly.1 1>&2 exit 1 fi fi if [ "$day_of_month" = 01 ] then # Srm -rf monthly.2 # Smv monthly.1 monthly.2 # Smkdir monthly.1 # Scp daily.1/* monthly.1/. if ! Srm -rf monthly.2 then echo Error rming monthly.2 1>&2 exit 1 fi if ! Smv monthly.1 monthly.2 then echo Error mving monthly.1 to monthly.2 1>&2 exit 1 fi if ! Smkdir monthly.1 then echo Error mkdiring monthly.1 1>&2 exit 1 fi if ! Scp "daily.1/*" "monthly.1/." then echo Error copying daily.1 to monthly.1 1>&2 exit 1 fi fi echo Backup finished at "`date`" echo Starting simplistic verification at "`date`" if [ 1 = 0 ] then FILE=/dev/null else FILE=/ptmp/strombrg/SRB.tvf fi if Restore.SRB -v daily.1 | gunzip -c | gtar tvf - > "$FILE" 2>&1 then echo Verification succeeded 1>&2 else echo Verification failed 1>&2 fi echo Simplistic verification finished at "`date`"