Please see this


Contents

- INDEX
- HP-UX Index
- Solaris
- Linux Index
- Other Unix types
- General Unix
- Unix Networking
- Unix Scripts
- Unix databases

Associated Information

- Unix Scripts Tips

Useful Links

- Bash shell HOWTO
- Bourne Shell Man Page
- C Shell Guide
- Korn Shell Resources

HP-UX Disaster Recovery Scripts

Run this script to save current server configuration

#!/bin/sh # ******************************************************************************* # Script to save configuration information for rebuilding HP Series 800 systems # ******************************************************************************* # Updated 10/11/97 - minor bug fix # Updated 30/12/97 - added code to check file type (hfs, vxfs, none, etc) # # This script is intended as a tool to aid in the recovery of systems. It should # not be relied on as the sole source for configuration information. Full # documentation of your system(s) is always advisable. # Check hostname and o/s version HOST=`hostname` VERS=`uname -r` # Get network information # Get ipaddresses (may be more than one card or multiple addresses on one card) lanscan | awk ' $5 ~ /lan/ { print $5 }' > /tmp/iface.$$ for if in `cat /tmp/iface.$$ ` do IPAD=`ifconfig $if | grep inet | cut -f2 -d" "` echo "$if $IPAD" >> /tmp/ip.$$ done # Print network information echo " " echo "Host: $HOST" echo "HP-UX version $VERS" echo " " echo "interfaces configured are as follows:" cat /tmp/ip.$$ echo " " rm /tmp/iface.$$ rm /tmp/ip.$$ # Find out disk/volume group configuration touch /tmp/pvinfo.$$ echo "Disk configuration is as follows:" echo " " echo " Device File Volume Grp Type Size" for disk in `ls /dev/dsk` do diskinfo /dev/rdsk/$disk > /dev/null 2>&1 if [ $? -eq 0 ]; then TYPE=`diskinfo /dev/rdsk/$disk` DISK=`echo $TYPE | grep -v CD-ROM | cut -f4,6 -d: | cut -f2,4 -d" "` echo $TYPE | grep CD-ROM > /dev/null if [ $? -eq 1 ]; then VGINFO=`pvdisplay /dev/dsk/$disk 2> /dev/null | \ awk ' $1 == "VG" { print $3 }'` PVINFO=`pvdisplay /dev/dsk/$disk 2> /dev/null | \ awk ' $1 == "PV" && $2 == "Name" { print $3 }'` echo "$PVINFO" | grep -q alternate if [ $? -eq 0 ]; then cat /tmp/pvinfo.$$ | grep -q /dev/dsk/$disk if [ $? -eq 0 ]; then echo "Alternate address $PVINFO $VGINFO $DISK Kb" >> /tmp/pvinfo.$$ else echo "/dev/dsk/$disk $VGINFO $DISK KB" >> /tmp/pvinfo.$$ fi else echo "/dev/dsk/$disk ${VGINFO:-**none**} $DISK Kb" >> /tmp/pvinfo.$$ fi fi fi done cat /tmp/pvinfo.$$ rm /tmp/pvinfo.$$ # Get logical volume information echo " " echo "Logical volumes defined are as follows:" echo " " LVS=`vgdisplay -v /dev/vg* | grep "LV Name"` echo "LV-Name VG-Name Perm status Mirror? Sched Size LE PE Stripe bad allocation" for lv in $LVS do if [ $lv != LV -a $lv != Name ]; then fs=`fstyp $lv 2> /dev/null` if [ "$fs" = "" ]; then fs=nofs fi output=`lvdisplay $lv | grep -v Logical` LVINFO=`echo $output | cut -f3,6,9,12,15,18,20,24,27,30,32,36,39,41 -d" "` echo $LVINFO $fs fi done echo " " echo "Details of /etc/fstab are as follows:" echo " " cat /etc/fstab # Other info that may be useful .... echo " " echo "ioscan information for reference purposes:" echo " " ioscan -f echo " " echo "Current swap configuration:" echo " " swapinfo -am echo " " echo "Current mounted file systems are:" echo " " df -k # N.B. df used in preference to bdf as output on one line..... #### END OF SCRIPT

This script will recreate Logical Volumes from data saved by getconfig.sh

#!/usr/bin/sh # ******************************************************************************* # Script to configure LVM and file systems for HP Series 800 systems # Tony Davis # # Usage: rebuild <scan>|<additional-lvspace-value> # # Change $CONFIG to the location of the file containing system configuration info # # Script rebuilds configuration from info attained by getconfig as follows: # 1. Find disks of same size or manually select them and pvcreate # 2. Create volume groups on the selected disks # 3. Create Logical volumes from config info # If this script is executed with the scan option, it displays information # about the root volume group configuration # If a number is provided as an arguement, this value is added to the size of # each logical volume # # Created 28/04/97 # Revised 07/07/97 - Changed to allocate disks in relation to space # required by volume group rather than by number # of disks on original system # Amended 22/10/97 - Added code to handle creating volume groups with # disks larger than 4Gb # Amended 11/11/97 - Changed coding to work out mount point from a df command # rather than bdf # Amended 30/12/97 - Amended calculations to be more accurate. # Added option to increase logical volume size. # Added code to update fstab and mount file systems # Changed code to cater for new version of getconfig which # specifies file types (to cater for raw partitions) # Amended 12/02/98 - Bug fixes # Amended 20/07/99 - Changed maths to use awk so results can be calculated # more accurately (to one decimal place) # Made sure mount points are created in right order # Display disk allocation and allow ammendement if # desired # Check enough disks for stripes (if not ignore option) # For swap issue swapon command # ******************************************************************************* # This script is intended as a tool to aid in the recovery of systems. It should # not be relied on as the sole mechanism for recovery of LVM configurations. # Full documentation of your system(s) is always advisable. # Routine to be invoked whenever this script exits tidy_up() { # Remove any temporary files created rm /tmp/vgsz.$$ > /dev/null 2>&1 rm /tmp/vgsz_sorted.$$ > /dev/null 2>&1 rm /tmp/disks_available.$$ > /dev/null 2>&1 rm /tmp/sorted_disks.$$ > /dev/null 2>&1 rm /tmp/build_info.$$ > /dev/null 2>&1 rm /tmp/build_info_sorted.$$ > /dev/null 2>&1 rm /tmp/lv1.$$ > /dev/null 2>&1 rm /tmp/lv2.$$ > /dev/null 2>&1 rm /tmp/diff.$$ > /dev/null 2>&1 rm /tmp/nice_diff.$$ > /dev/null 2>&1 exit } # Set trap conditions trap "tidy_up" 0 1 2 3 15 # Script proper starts here! CONFIG=/home/smg/davist4/weldev01.config # Check config file exists if [ ! -f $CONFIG ]; then echo "Configuration file $CONFIG does not exist" echo "Please edit the CONFIG variable in this script and try again" exit 1 fi # If scan arguement given, script prints info about root volume group # which is required for the initial setup # If number provided as arguement, this value is added to the logical volume size ADD=0 # set initial extra lv space requirement if [ $# -gt 0 ]; then if [ $1 != "scan" ]; then # Check if arguement is a number echo $1 | grep '[0-9][0-9]*' > /dev/null if [ $? -eq 0 ]; then ADD=$1 else echo "USAGE: rebuild <scan>|<additional-lvspace-value> " exit 1 fi else echo "The following information is required to set up the root volume group" echo " " echo "Physical volumes configured are:" grep /dev/dsk $CONFIG | grep vg00 echo " " for LVOL in `grep vg00 $CONFIG | egrep "vxfs|hfs" | awk '{ print $1 }'` do DIR=`grep $LVOL $CONFIG | egrep "vxfs|hfs" | awk '{ print $2 }'` SIZE=`grep $LVOL $CONFIG | egrep -v "vxfs|hfs" | awk '{ print $8}'` echo " The size of $DIR is $SIZE Mb (Logical volume $LVOL)" done echo " " echo "Swap sizes (in Mb) are as follows:" echo " " grep "dev " $CONFIG | awk ' {print $2, $9}' exit 0 fi fi # First off we're going to pvcreate all the free disks whether they're required # or not. This will ensure they really exist and from this we can build a # table of available disks and their size DISKSUSED=`vgdisplay -v /dev/vg* | awk ' $3 ~ /\/dev\/dsk/ { print $3 }'` echo "pvcreating free disks ....." for Disk in `ls /dev/dsk` do echo $DISKSUSED | grep -q /dev/dsk/$Disk if [ $? -eq 1 ]; then # Disk not already in use so OK to pvcreate it pvcreate -f /dev/rdsk/$Disk 2> /dev/null if [ $? -eq 0 ]; then # Disk really exists so lets add it to the availabilty table DISKGB=`diskinfo -b /dev/rdsk/$Disk | \ awk '{ result = $1 / 1000000 } { printf("%.1f", result) }'` echo /dev/dsk/$Disk $DISKGB >> /tmp/disks_available.$$ fi fi done # Sort the table with smallest volume group first # ( makes allocating disks to the volume group easier later) sort -k 2,2 /tmp/disks_available.$$ > /tmp/sorted_disks.$$ # Work out the amount of space required for each volume group and allocate disks # Find out sizes of volume groups required from config file touch /tmp/build_info.$$ # Work out the size required for each volume group and write to a temp file cat $CONFIG | awk \ '$1 ~ /\/dev\/dsk\// {vg[$2] += $4 / 1000000 } END { for (name in vg) printf "%s\t%10.1f\n", name, vg[name] }' > /tmp/vgsz.$$ # sort in order of smallest volume group first sort -k 2,2 /tmp/vgsz.$$ > /tmp/vgsz_sorted.$$ # Now read in the size by volume group info and check what disks there # are to satisfy these requirements cat /tmp/vgsz_sorted.$$ | while read volgrp size do vgrpstart=`echo "$volgrp" | cut -c1-7` if [ "$volgrp" != "**none**" -a "$vgrpstart" = "/dev/vg" ]; then #Ignore unused disks SPACE=notenough # Set loop flag Gb=$size echo "Space required for $volgrp is $Gb Gb" # OK, now we know how much space we need for the volume group, # let's loop round checking disks available until each volume group # has enough space or we run out of disks..... while [ "$SPACE" != "OK" ] do # If we're checking the root volume group, find out how much space # is already allocated if [ "$volgrp" = "/dev/vg00" ]; then TOTALGb=0 VG00DISK=`vgdisplay -v /dev/vg00 | grep "/dev/dsk/" | awk \ ' BEGIN { FS = "/" } { print $4 } '` # Do a loop in case more than one physical volume in vg00 for DisK in $VG00DISK do SUBTOTALGb=`diskinfo -b /dev/rdsk/$DisK | \ awk '{ result = $1 / 1000000 } { printf("%.1f", result) }'` TOTALGb=`echo $TOTALGb $SUBTOTALGb | \ awk '{ result2 = $1 + $2 } { printf("%.1f", result2) }'` # If vg00 already has enough space set flag to indicate this if [ "$TOTALGb" -eq "$Gb" ]; then SPACE=OK fi done echo "Volume group /dev/vg00 already has $TOTALGb Gb allocated" else TOTALGb=0 fi # Start assigning disks EDITED=no cat /tmp/sorted_disks.$$ | while read device Size do if [ "$SPACE" = "notenough" ]; then # Check if this disk has already been allocated grep -q $device /tmp/build_info.$$ # OK, disk isn't already allocated if [ $? -eq 1 ]; then echo "Using disk $device (size $Size Gb) for volume group $volgrp" echo "$device" $volgrp $Size >> /tmp/build_info.$$ # This is how much space we have allocated so far TOTALGb=`echo $TOTALGb $Size | \ awk '{ result2 = $1 + $2 } { printf("%.1f", result2) }'` if [ $TOTALGb -ge $Gb ]; then # If we have enough space, exit the loop SPACE=OK echo " " echo "Space allocated to $volgrp is $TOTALGb Gb" sleep 1 echo " " fi fi fi done # Oh dear, we've checked all the available disks and still haven't # got enough space! Let's leave it to the users discretion whether # enough has been allocated. if [ "$SPACE" = "notenough" ]; then echo "Sorry, there are no more disks available" echo "Only able to allocate $TOTALGb Gb of $Gb Gb required" echo "Do you want to continue with this allocation? [y] or [n]:\c" read reply < /dev/console if [ "$reply" = "y" -o "$reply" = "Y" ]; then SPACE=OK echo " " echo "Space allocated to $volgrp is $TOTALGb Gb" echo " " else echo "Do you want to manually allocate disks to volume groups? [y] or [n]:\c" read reply2 < /dev/console if [ "$reply2" = "y" -o "$reply2" = "Y" ]; then echo "You will now enter a vi editing session" echo "Edit this file changing the disk allocations as required" echo "Once completed, save and quit in the normal way" sleep 10 echo " " echo "The space required by the volume groups is as follows:" echo "Please note the sizes so disks can be suitably allocated" echo "Volume Group Size" echo "==========================" cat /tmp/vgsz.$$ | grep -v "**none**" echo "Press return to continue\c" read return0 < /dev/console vi /tmp/build_info.$$ < /dev/console SPACE=OK EDITED=yes else echo "Program exiting Return Code 1, No more disks" exit 1 fi fi fi done fi done # Show how disks allocated and allow user to edit if they choose if [ "$EDITED" != yes ]; then VG00SZ=`vgdisplay /dev/vg00 | grep "Total PE" | \ awk '{ result3 = $3 * 4 / 1000 } { printf("%.1f", result3) }'` echo "\nThe space required for the volume groups is:" echo "Volume Group Size" echo "==========================" cat /tmp/vgsz.$$ | grep -v "**none**" echo "\nThe disks are currently allocated as follows:" echo "Disk VolGroup Gb" echo "=============================" cat /tmp/build_info.$$ echo "\nNote: vg00 already has $VG00SZ Gb allocated to it\n" echo "Press return to continue\c" read return1 </dev/console echo "Do you want to change the disk allocation? [y] or [n]:\c" read reply3 < /dev/console if [ "$reply3" = "y" -o "$reply2" = "Y" ]; then echo "You will now enter a vi editing session" echo "Edit this file changing the disk allocations as required" echo "Once completed, save and quit in the normal way" sleep 10 echo " " echo "The space required by the volume groups is as follows:" echo "Please note the sizes so disks can be suitably allocated" cat /tmp/vgsz.$$ | grep -v "**none**" echo "Press return to continue\c" read return2 < /dev/console vi /tmp/build_info.$$ < /dev/console fi fi #Now we're going to create the volume groups on the selected disks..... VOLUMEGRP=unset sort -k 2,2 /tmp/build_info.$$ > /tmp/build_info_sorted.$$ # Code to cater to large disks requiring more extents # Max extents is set to the value of that required by the largest disk MAXSIZE=4 vgarg="" cat /tmp/build_info_sorted.$$ | while read dev vg sz do if [ "$sz" -gt 4 ]; then if [ "$sz" -gt $MAXSIZE ]; then MAXSIZE=$sz extents=`expr $MAXSIZE / 4 \* 1016` vgarg="-e $extents" fi fi done cat /tmp/build_info_sorted.$$ | while read dev volgrp size do if [ $VOLUMEGRP = unset -o $VOLUMEGRP != $volgrp ]; then if [ $volgrp != "/dev/vg00" ]; then mkdir $volgrp cd $volgrp # Work out what the minor number should be for the group file NUM=0 # set minor number variable to zero for dir in `ls -d /dev/vg*` do minor=`ll $dir | awk '/group/ { print $6 }' | cut -c4` if [ "$minor" -gt $NUM ]; then NUM=$minor fi done mnum=`expr $NUM + 1` mknod group c 64 0x0"$mnum"0000 vgcreate $vgarg $volgrp $dev VOLUMEGRP=$volgrp else vgextend $volgrp $dev VOLUMEGRP=$volgrp fi else vgextend $volgrp $dev fi done # Now we're going to check the configuration information file to ascertain # what logical volumes need to be created. We'll check what already exists # to see if it matches what's in the config file. If it doesn't, a # warning will be issued showing the difference(s) # Any that don't already exist, we'll create. # Check what logical volumes currently exist LVS=`vgdisplay -v /dev/vg* | grep "LV Name"` for lv in $LVS do if [ $lv != LV -a $lv != Name ]; then # Trim the output loosing the comments so only the actual lv info remains output=`lvdisplay $lv | grep -v Logical` LVINFO=`echo $output | cut -f3,6,9,12,15,18,20,24,27,30,32,36,39,41 -d" "` echo $LVINFO > /tmp/lv1.$$ check=`cat /tmp/lv1.$$ | cut -f1,2 -d" "` # Check if logical volume should exist cat $CONFIG | grep "$check" > /tmp/lv2.$$ if [ $? = 0 ]; then # If it does check that it is configured correctly diff /tmp/lv1.$$ /tmp/lv2.$$ > /tmp/diff.$$ 2>&1 if [ $? = 0 ]; then echo "$check aleady configured correctly" else echo " " echo "# WARNING: $check does not exactly match original configuration" echo "# WARNING: see /tmp/mismatch.log for details" echo " " # Format the differences file to provide a readable message echo " LV-Name VG-Name Perm status Mirror? Sched Size LE PE Strp bad" > /tmp/nice_diff.$$ echo "< current config" >> /tmp/nice_diff.$$ cat /tmp/diff.$$ | grep /dev/vg >> /tmp/nice_diff.$$ echo "> expected config" >> /tmp/nice_diff.$$ cp /tmp/nice_diff.$$ /tmp/mismatch.log echo "Use lvchange/lvextend to make required changes" >> /tmp/mismatch.log echo " " sleep 5 fi fi fi done # Now create any logical volumes that don't already exist for newlv in `cat $CONFIG | awk ' $1 ~ /^\/dev\/vg/ { print $1 }'` do lvdisplay $newlv > /dev/null 2>&1 if [ $? -ne 0 ]; then newlvcfg=`cat $CONFIG | grep $newlv` newname=`echo $newlvcfg | cut -f4 -d/` newvg=`echo $newlvcfg | cut -f2 -d" "` newperm=`echo $newlvcfg | cut -f3 -d" "` newavail=`echo $newlvcfg | cut -f4 -d" "` newmirr=`echo $newlvcfg | cut -f5 -d" "` newrecv=`echo $newlvcfg | cut -f6 -d" "` newsched=`echo $newlvcfg | cut -f7 -d" "` newsize=`echo $newlvcfg | cut -f8 -d" "` newpe=`echo $newlvcfg | cut -f9 -d" "` newle=`echo $newlvcfg | cut -f10 -d" "` newstripe=`echo $newlvcfg | cut -f11 -d" "` newstrpsz=`echo $newlvcfg | cut -f12 -d" "` newbadblk=`echo $newlvcfg | cut -f13 -d" "` newalloc=`echo $newlvcfg | cut -f14 -d" "` fstype=`echo $newlvcfg | cut -f15 -d" "` # Set up command string parameters if [ "$newperm" != "read/write" ]; then P="-p r" else P="-p w" fi if [ "$newavail" != "available/syncd" ]; then a="-a n" else a="-a y" fi if [ "newmirr" -ne "0" ]; then m="-m $newmirr" else m="-m 0" fi if [ "$newrecv" != "MWC" ]; then M="-M n" else M="-M y" fi if [ "$newsched" != "parallel" ]; then d="-d s" else d="-d p" fi # Add additional space requested as arguement to script if [ "$ADD" -ne "0" ]; then newsize=`expr $newsize + $ADD` fi L="-L $newsize" if [ "$newstripe" -ne 0 ]; then # Check there's enough volumes to create the stripes STRPVG=`echo $newlv | awk 'BEGIN { FS = "/" } { print $3}'` STRPDSKS=`vgdisplay -v /dev/$STRPVG | grep dsk | wc -l` if [ "STRPDSKS" -ge "$newstripe" ]; then i="-i $newstripe -I $newstrpsz" else echo "WARNING: Not enough disks in volume group $STRPVG to create striping" fi fi if [ "$newbadblk" != on ]; then r="-r n" else r="-r y" fi if [ "$newalloc" != strict ]; then s="-s y -C y" fi lvcreate $P $d $L $r $c -n $newname $newvg # lvextend $m $M $newvg/$newname # If mirror copies needed (not licenced yet) lvchange $a $newvg/$newname # Now create the filesystem of the right type # Coding to cater for old version of getconfig (filetype not checked) if [ "$fstype" = "" ]; then fstype=`grep "$newvg/$newname" $CONFIG | awk '/(vxfs|hfs|swap)/ {print $3}'` fi # Only newfs and create mount point if valid file system if [ "${fstype:-vxfs}" != "nofs" -a "${fstype:-vxfs}" != "swap" ]; then newfs -F ${fstype:-vxfs} $newvg/r$newname else # If it's swap isssue swapon command grep $newvg/$newname $CONFIG | grep -q swap if [ $? = 0 ]; then swapon $newvg/$newname fi fi fi done # Now create create mount point if necessary and mount filesystems # Note: sort important on next line to ensure mount points made in sequence cat $CONFIG | grep "(/dev/vg" | sort -n | while read MOUNT LOCATION other do bdf | grep -q $MOUNT # check if filesystem already mounted if [ $? != 0 ]; then if [ ! -d $MOUNT ]; then mkdir -p $MOUNT fi # remove leading bracket "(" LOCATION2=`echo "$LOCATION" | awk 'BEGIN { FS = "(" } { print $2 }'` mount $LOCATION2 $MOUNT fi done # Copy fstab in to place cp /etc/fstab /etc/fstab.orig # edit contents of config file so only fstab remains and copy in place sed -e '1,/Details/d;/ioscan/,$d' < $CONFIG > /etc/fstab # Show what's mounted and swap available bdf swapinfo -a echo "Logical Volume Configuration has completed" echo "Please check results against desired configuration"

The following script will delete all volume groups except vg00 in the event there's a problem during the running of the rebuild.sh script

#!/usr/bin/sh # ******************************************************************************* # Script to reset LVM config back to base if problems while running rebuild # # Enter volume groups to be removed in variable $VOLGRPS # # ******************************************************************************* # This script is intended as a tool to aid in the recovery of systems. It will # destroy volume groups and should be used with care. VOLGRPS="vg01 vg02 vg03" echo "This script will remove Volume Groups $VOLGRPS" echo "Do you wish to continue? [y] or [n]:\c" read ans if [ "$ans" = "n" -o "$ans" = "N" ]; then exit fi for vg in $VOLGRPS do for lv in `vgdisplay -v /dev/$vg | awk ' /LV Name/ { print $3 }'` do lvremove $lv done for dsk in `vgdisplay -v /dev/$vg | awk ' /PV Name/ { print $3 }'` do vgreduce /dev/$vg $dsk if [ $? != 0 ]; then vgremove /dev/$vg $dsk fi done rm /dev/$vg/* rmdir /dev/$vg done if [ -f /etc/fstab.orig ]; then echo "Overwriting /etc/fstab with /etc/fstab.orig" echo "Do you wish to continue? [y] or [n]:\c" read ans2 if [ "$ans2" = "y" -o "$ans2" = "Y" ]; then mv /etc/fstab.orig /etc/fstab fi fi

Copyright 2000 Intronet Computers Ltd
Email: Intronet Computers for enquiries