source: gpfs_3.1_ker2.6.20/lpp/mmfs/bin/mmbackup @ 177

Last change on this file since 177 was 16, checked in by rock, 17 years ago
  • Property svn:executable set to *
File size: 10.7 KB
RevLine 
[16]1#!/bin/ksh
2# IBM_PROLOG_BEGIN_TAG
3# This is an automatically generated prolog.
4
5
6
7# Licensed Materials - Property of IBM
8
9# (C) COPYRIGHT International Business Machines Corp. 2002,2006
10# All Rights Reserved
11
12# US Government Users Restricted Rights - Use, duplication or
13# disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
14
15# IBM_PROLOG_END_TAG
16# @(#)65 1.25.1.2 src/avs/fs/mmfs/ts/admin/mmbackup.sh, mmfs, avs_rgpfs24, rgpfs24s005a 6/14/06 14:39:45
17##############################################################################
18#
19# Usage:
20#
21#   mmbackup Device -n ControlFile [-t {full | incremental}] [-r IOrate]
22#                     [-s sortDir] [-T]
23#
24#     or
25#
26#   mmbackup Device -R [-r IOrate] [-s sortDir] [-T]
27#
28# where:
29#
30#   -n ControlFile         is a file containing information for controlling
31#                          the backup; this parameter is optional if mmbackup
32#                          was run previously, in which case the values from
33#                          the prior control file remain in effect if -n
34#                          is not specified
35#
36#   -r IOrate              an integer between 1 and 100 specifying how much
37#                          I/O bandwidth to allocate to the backup process
38#                          (the larger the number, the larger the allocated
39#                          bandwidth; default is 100)
40#
41#   -t full | incremental  type of backup; default is incremental
42#
43#   -R                     resume backing up files which failed to be
44#                          backed up on the previous invocation of mmbackup
45#
46#   -T                     enable tracing
47#
48#   -s sortDir             sort temporary directory name (default /tmp)
49#
50##############################################################################
51
52# Include global declarations and service routines.
53. /usr/lpp/mmfs/bin/mmglobfuncs
54. /usr/lpp/mmfs/bin/mmsdrfsdef
55. /usr/lpp/mmfs/bin/mmfsfuncs
56
57sourceFile="mmbackup.sh"
58[[ -n $DEBUG || -n $DEBUGmmbackup ]] && set -x
59$mmTRACE_ENTER "$*"
60
61
62# Local work files.  Names should be of the form:
63#   fn=${tmpDir}fn.${mmcmd}.$$
64
65tmpCtrlFile=${tmpDir}tmpCtrlFile.mmbackup.$$
66LOCAL_FILES=" $tmpCtrlFile "
67
68
69# Local variables
70
71usageMsg=458
72integer rc=0
73integer nodeCount=0
74integer n
75backupControlFile=".mmbuControl"
76
77typeset -i freeSpace
78
79
80# Local routines
81
82
83##########################################################################
84#
85# Function:  Get the amount of unused space in the specified file system.
86#
87# Input:     $1 - file system dev name or name of a file or directory
88#
89# Output:    the number of unused 1K blocks in the filesystem
90#
91# Returns:   0
92#
93##########################################################################
94function getFreeSpace  # { <fileSytem> | <fileName> }
95{
96  typeset sourceFile="mmbackup.sh"
97  [[ -n $DEBUG || -n $DEBUGgetFreeSpace ]] && set -x
98  $mmTRACE_ENTER "$*"
99  typeset fileSystem=$1
100
101  typeset dfInfo
102  typeset -i freeBlocks
103
104  [[ -z $fileSystem ]] && \
105    checkForErrors "getFreeSpace: missing file system parameter" 1
106
107  # Issue the df command, requesting info in Posix format and 1K blocks.
108  LC_ALL=C $df -P -k $fileSystem > $tmpfile
109
110  # Read and discard the first line (the header).
111  exec 3<&-
112  exec 3< $tmpfile
113  $rm -f $tmpfile
114  read -u3 dfInfo
115
116  # Read and extract the desired info from the second line.
117  read -u3 dfInfo
118  set -f ; set -- $dfInfo ; set +f
119  freeBlocks=$4
120
121  # Return the result.
122  print -- "$freeBlocks"
123  return 0
124
125}  #--------- end of function getFreeSpace ------------------
126
127
128
129######################
130# Mainline processing
131######################
132
133
134#################################
135# Process the command arguments.
136#################################
137[[ $arg1 = '-?' || $arg1 = '-h' || $arg1 = '--help' || $arg1 = '--' ]] && \
138  syntaxError "help" $usageMsg
139
140[[ $argc -lt 1  ]] && \
141  syntaxError "missingArgs" $usageMsg
142
143device=$arg1     # Save the file system name (always the first parameter).
144shift 1          # Drop the device name from the parameter list.
145
146while getopts :n:r:RTt:s: OPT
147do
148  case $OPT in
149
150    n) # input control file
151       [[ -n $nflag ]] && syntaxError "multiple" $noUsageMsg "-$OPT"
152       nflag="-$OPT"; narg=$OPTARG;
153       [[ -n $Rflag ]] && \
154         syntaxError "invalidCombination" $usageMsg "-n" "-R"
155       ;;
156
157    r) [[ -n $rflag ]] && syntaxError "multiple" $noUsageMsg "-$OPT"
158       rflag="-$OPT"; rarg=$OPTARG;
159       # Ensure that rarg is an integer, and that its value is from 1 to 100.
160       n=$(checkIntRange $rflag $rarg 1 100)
161       [[ $? -ne 0 ]] && cleanupAndExit
162       ;;
163
164    s) [[ -n $sflag ]] && syntaxError "multiple" $noUsageMsg "-$OPT"
165       sflag="-$OPT"; sarg=$OPTARG;
166       ;;
167
168    R) [[ -n $Rflag ]] && syntaxError "multiple" $noUsageMsg "-$OPT"
169       Rflag="-$OPT";
170       [[ -n $nflag ]] && \
171         syntaxError "invalidCombination" $usageMsg "-n" "-R"
172       [[ -n $tflag ]] && \
173         syntaxError "invalidCombination" $usageMsg "-t" "-R"
174       ;;
175
176    t) [[ -n $tflag ]] && syntaxError "multiple" $noUsageMsg "-$OPT"
177       tflag="-$OPT"; targ=$OPTARG;
178       [[ $targ != full && $targ != incremental ]] && \
179         syntaxError "invalidOption" $usageMsg "-$OPT $OPTARG"
180       [[ -n $Rflag ]] && \
181         syntaxError "invalidCombination" $usageMsg "-t" "-R"
182       ;;
183
184    T) Tflag="-T";
185       ;;
186
187    +[n,r,s,R,t]) # Invalid option
188       syntaxError "invalidOption" $usageMsg $OPT
189       ;;
190
191    :) # Missing argument
192       syntaxError "missingValue" $usageMsg $OPTARG
193       ;;
194
195    *) # Invalid option
196       syntaxError "invalidOption" $usageMsg $OPTARG
197       ;;
198
199  esac
200
201done
202
203shift OPTIND-1
204[[ $# != 0 ]] && syntaxError "extraArg" $usageMsg $1
205
206# Complete the parameter checking and set defaults.
207[[ -z $nflag && -z $Rflag ]] && \
208  syntaxError "missingArgs" $usageMsg
209
210[[ -z $rarg ]] && rarg=100
211rOption="-r $rarg"
212
213if [[ -z $targ ]]
214then
215  if [[ -z $Rflag ]]
216  then
217    tOption="-t incremental"
218  else
219    tOption=""
220  fi
221else
222  tOption="-t $targ"
223fi
224
225sOption=""
226if [[ -n $sarg ]]
227then
228  if [[ ! -d  $sarg ]]
229  then
230    # The sort temp dir does not exist.  Issue an error and quit.
231    printErrorMsg 574 $mmcmd $sarg
232    cleanupAndExit
233  fi
234  sOption="-s $sarg"
235fi
236
237
238#######################################################
239# Make sure there is a reasonable amount of free space
240# in the /var/mmfs filesystem.  This is needed so that
241# TSM can create error logs in /var/mmfs/mmbackup.
242#######################################################
243freeSpace=$(getFreeSpace $mmbackupDir)
244if [[ $freeSpace -lt 100 ]]
245then
246  # The filesystem is not mounted.  Issue an error and quit.
247  printErrorMsg 572 $mmcmd $mmbackupDir "100K"
248  cleanupAndExit
249fi
250
251
252########################################################################
253# Set up trap exception handling and call the gpfsInit function.
254# It will ensure that the local copy of the mmsdrfs and the rest of the
255# GPFS system files are up-to-date.  There is no need to lock the sdr.
256########################################################################
257trap pretrap2 HUP INT QUIT KILL
258gpfsInitOutput=$(gpfsInit nolock)
259setGlobalVar $? $gpfsInitOutput
260
261# Determine the lookup order for resolving host names.
262[[ $osName != AIX ]] && resolveOrder=$(setHostResolveOrder)
263
264
265#######################################################
266# Make sure the file system exists, that it is part of
267# this node's cluster, and that it is mounted.
268#######################################################
269findFSoutput=$(findFS "$device" $mmsdrfsFile)
270[[ -z $findFSoutput ]] && cleanupAndExit
271
272# Parse the output from the findFS function.
273set -f ; set -- $findFSoutput ; set +f
274fqDeviceName=$1
275fsHomeCluster=$3
276
277# Exit with a message if the command was invoked for a remote file system.
278if [[ $fsHomeCluster != $HOME_CLUSTER ]]
279then
280  # Command is not allowed for remote file systems.
281  printErrorMsg 106 $mmcmd $device $fsHomeCluster
282  cleanupAndExit 1
283fi
284
285# Obtain the name of the file system (i.e., the mount point).
286mountPoint=$(findMountpoint $fqDeviceName)
287if [[ $mountPoint = "" ]]
288then
289  # The filesystem is not mounted.  Issue an error and quit.
290  printErrorMsg 563 $mmcmd $device $ourNodeName
291  cleanupAndExit
292fi
293
294
295##########################################################
296# Check that the control file, if specified, makes sense.
297##########################################################
298if [[ -z $narg ]]
299then
300  nOption=""
301else
302  # Verify the existence of the user specified control file
303  # and create our own copy.
304  checkUserFile $narg $tmpCtrlFile
305  [[ $? -ne 0 ]] && cleanupAndExit
306
307  # Set nOption to pass the control file to tsbackup.
308  nOption="-n $tmpCtrlFile"
309
310  # Check whether the backup clients specified in the control file
311  # belong to the cluster.
312  foundError=false
313  IFS_sv="$IFS"  # Save the IFS variable.
314  exec 3<&-
315  exec 3< $tmpCtrlFile
316  while read -u3 inputLine
317  do
318    IFS="="
319    set -f ; set -- $inputLine ; set +f
320    lineType=$1
321    lineValue=$2
322    IFS="$IFS_sv"  # Restore the IFS variable.
323    if [[ $lineType = clientName ]]
324    then
325      # Find the IP address that corresponds to this node name.
326      hostResult=$($host $lineValue)
327      set -f ; set -- $hostResult ; set +f
328      ipa=${3%%,*}           # Exclude everything after the first comma.
329      if [[ -z $ipa ]]
330      then
331        # An invalid node name was specified as a client.
332        printErrorMsg 54 $mmcmd $lineValue
333        foundError=true
334      fi
335      nodeName=$(getNodeInfo  \
336                   $REL_HOSTNAME_Field $IPA_Field $ipa $nsId $mmsdrfsFile)
337      if [[ -z $nodeName ]]
338      then
339        # The specified client node is not a member of the GPFS cluster.
340        printErrorMsg 290 $mmcmd $lineValue
341        foundError=true
342      fi
343    fi
344  done  # end while read -u3 fileName
345
346  # If an error was found, print a "command failed" message and exit.
347  if [[ $foundError = true ]]
348  then
349    printErrorMsg 389 $mmcmd
350    cleanupAndExit
351  fi
352fi
353
354
355################################################################
356# If an incremental or a resume backup was specified, make sure
357# there is a readable backup control file from a prior backup.
358################################################################
359if [[ $targ = incremental || -n $Rflag ]]
360then
361  myBackupCtrlFile="$mountPoint/$backupControlFile"
362  if [[ ! -f $myBackupCtrlFile || ! -r $myBackupCtrlFile ]]
363  then
364    # Can't find or read the backup control file from a prior backup.
365    printErrorMsg 565 $mmcmd $myBackupCtrlFile
366    cleanupAndExit
367  fi
368fi
369
370
371####################################
372# Invoke tsbackup to do the backup.
373####################################
374$tsbackup $fqDeviceName $mountPoint $nOption $rOption $tOption $Rflag $Tflag $sOption
375rc=$?
376if [[ $rc -ne 0 ]]
377then
378  # The command failed.
379  printErrorMsg 389 $mmcmd
380else
381  # The command completed successfully.
382  printInfoMsg 272 $mmcmd
383fi
384
385cleanupAndExit $rc
386
Note: See TracBrowser for help on using the repository browser.