1#!/bin/bash 2 3# Repeatedly copy files to NFS server. 4 5# Copyright (C) 2003-2006 IBM 6# 7# This program is free software; you can redistribute it and/or 8# modify it under the terms of the GNU General Public License as 9# published by the Free Software Foundation; either version 2 of the 10# License, or (at your option) any later version. 11# 12# This program is distributed in the hope that it will be useful, but 13# WITHOUT ANY WARRANTY; without even the implied warranty of 14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15# General Public License for more details. 16# 17# You should have received a copy of the GNU General Public License 18# along with this program; if not, write to the Free Software 19# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 20# 02111-1307, USA. 21 22if [ -z "$NFS_SERVER" -o "$NFS_SERVER" == "0" ]; then 23 echo "NFS server not configured." 24 exit 255 25fi 26 27SHORTHOST=`echo "$HOSTNAME" | sed -e 's/\..*//g'` 28 29# set up to delete nfs data and unmount nfs when we die 30NFSMOUNT=/pounder 31NFSLOCAL="$POUNDER_TMPDIR/nfs-$$" 32trap 'echo Cleaning up...; mv $NFSLOCAL/$SHORTHOST/testnet $NFSLOCAL/$SHORTHOST/testnet.del; rm -rf $NFSLOCAL/$SHORTHOST/testnet.del; umount $NFSLOCAL; rm -rf $NFSLOCAL; echo Clean.; exit 0' 1 2 15 33 34[ ! -x $NFSLOCAL ] && mkdir $NFSLOCAL 35echo "Mounting remote storage via NFS..." 36 37echo Mounting $NFS_SERVER:$NFSMOUNT on $NFSLOCAL... 38 39# Did we see any failures? 40LOGFILE=/proc/$$/fd/1 41OLD_ERRORS=`egrep -ic "(err|fail|cannot|invalid|denied)" $LOGFILE` 42 43if (mount "$NFS_SERVER:$NFSMOUNT" $NFSLOCAL -t nfs -o tcp); then 44 # Create a dir for this machine and sleep to give our mkdir a 45 # better chance of making it. 46 [ ! -x $NFSLOCAL/$SHORTHOST ] && mkdir $NFSLOCAL/$SHORTHOST 47 sleep 5 48 49 # If we've already stuff here, move it and delete it. 50 # Meanwhile, create ourselves a new directory for the copy 51 [ -x $NFSLOCAL/$SHORTHOST/testnet ] && \ 52 mv $NFSLOCAL/$SHORTHOST/testnet $NFSLOCAL/$SHORTHOST/testnet.del 53 [ -x $NFSLOCAL/$SHORTHOST/testnet.del ] && \ 54 rm -rf $NFSLOCAL/$SHORTHOST/testnet.del & 55 56 # Actually copy data... 57 echo "Remote NFS copy in progress..." 58 cp -pr /usr $NFSLOCAL/$SHORTHOST/testnet 59 60 # Now diff it... 61 diff -Naur /usr $NFSLOCAL/$SHORTHOST/testnet > $POUNDER_TMPDIR/nfs.diff 62 63 # Now remove it 64 rm -rf $NFSLOCAL/$SHORTHOST/testnet 65 66 # and unmount 67 umount $NFSLOCAL 68 rm -rf $NFSLOCAL 69else 70 echo Unable to connect to the NFS server $NFS_SERVER. 71 echo Please check network configuration and update the script. 72 exit -1 73fi 74 75# Anything in the diff? 76DIFF_ERRORS=`wc -l < $POUNDER_TMPDIR/nfs.diff` 77if [ $DIFF_ERRORS -gt 0 ]; then 78 exit $DIFF_ERRORS 79fi 80 81# Did we see any failures? 82NEW_ERRORS=`egrep -ic "(err|fail|cannot|invalid|denied)" $LOGFILE` 83ERRORS=$((NEW_ERRORS - OLD_ERRORS)) 84if [ $ERRORS -eq 255 ]; then 85 ERRORS=254 86fi 87exit $ERRORS 88 89