Parent document is top of "comp.unix.aix Frequently Asked Questions (Part 5 of 5)"
Previous document is "8.06: How do I do remote backup?"
Next document is "8.07: How to configure dialup SLIP"

8.06: How do I do remote backup? (cont.)

From: Henk van Doorn <hvdoorn@xs4all.nl>

#!/bin/ksh
#######################################################################
#     rmksysb                                                         #
#######################################################################
#                                                                     #
# Description:                                                        #
#       creates a bootable mksysb backup of a remote system running   #
#	AIX 3.x or lists the Table of Contents of the current tape    #
#                                                                     #
# Usage:                                                              #
#       ./rmksysb $1 [$2] 					      #
#		$1 - remote host to be backed up		      #
#		$2 - optional: local tape device (default: rmt0)      #
#	or:							      #	
#	./rmksysb -l [$2]                                             #
#		to list Table of Contents saveset on tape in $2	      #
#		(only useful on tapes created by rmksysb)	      #
#                                                                     #
# Output:                                                             #
#       a bootable mksysb of the remote system                        #
#	or a listing of the TOC saveset on the current tape	      #
#                                                                     #
# Remarks:							      #
#	. rmksysb can only be used by root			      #	
#	. this script will use tapedevice .1, so if 	  	      #
#	  a >2.3GB drive is used: check density_set_1	              #
#	. the remote host needs /.rhosts to include the local host    #
#	  for root access (+ shell enabled in /etc/inetd.conf)        #	
#	. you will need some room (>1.5MB) on /tmp on the remote host #
#	  for standard mksysb .archive.list.* etc.		      #
#	. remote standard output & standard error (except dd/chdev)   #
#	  will go to local stdout & stderr			      #
#	. redirecting stdout can create quite large log-files (2MB)   #
#	. AIX versions should not be too far apart as the boot-saveset#
#	  comes from the local system & the rest from the remote      #
#	  (tested on AIX 3.2.5, AIX 4+ definitely won't work!!!)      #
#	. most likely this script will fail with multi-tape mksysb's: #
#	  another incentive to keep rootvg as small as possible!      #
#								      #
# Author:							      #
#	Henk van Doorn						      #
#	Email: hvdoorn@xs4all.nl       				      #
#								      #
#	Thanks to all who contributed. Esp. Paul Wynn (AIXpert '93),  #
#	my colleagues Dominic Dinardo & Douwe van Terwisga	      #
#	+ the input from Usenet were stimulating; thanks folks!	      #
#	I would welcome any additions & changes for the better...     # 
#                                                                     #
#######################################################################
#         CHANGES                                                     #
#######################################################################
#                                                                     #
# ID	 WHO   DATE                        DESCR                      #
# --	 ---   -------  --------------------------------------------- #
# X000	 HvD   6Jan95   Created this file.                            #
# X001	 HvD   2Feb95   Final version                                 #
#######################################################################

set +u

# Global variable definitions.
UMASK=`umask`
BLK_SZ=1024
BOOT_BLK_SZ=512
HOST=${1}

# TAPE = $2 with /dev/ & .* removed, defaulting to rmt0
TAPE=${2:-rmt0}
TAPE=${TAPE#/dev/}
TAPE=${TAPE%.*}

usage()
{
    echo "Usage: ./rmksysb <remote_host_name> [<tape_device>] or" >&2
    echo "       ./rmksysb -l [<tape_device>]" >&2
    echo "                 with <tape_device>= e.g. rmt1" >&2
    echo "Default <tape_device>=rmt0" >&2
    return
}

check_parms()
{
if [ "${HOST}" = "" ]
then
	usage
	exit 1
fi

if [ "${HOST}" = "-l" ]
then
# show TOC block which contains some backup details on rmksysb tapes
	get_tape_block_size
	chdev -l ${TAPE} -a block_size=${BOOT_BLK_SZ} >/dev/null 2>&1
	mt -f /dev/${TAPE} rewind
	mt -f /dev/${TAPE}.1 fsf 2
	dd if=/dev/${TAPE} count=1 2>/dev/null
	chdev -l ${TAPE} -a block_size=${OLD_BLK_SZ} >/dev/null 2>&1
	exit 
fi
}

check_host()
{
rsh ${HOST} hostname >/dev/null 2>&1
if [ $? -ne 0 ]
then
	echo "Check hostname & rsh access" >&2
	exit 1
fi
}

get_tape_block_size()
{
VALID=
`lsdev -Cc tape | cut -f1 -d" " | grep ${TAPE} 2>&1 >/dev/null` && 
	{
        OLD_BLK_SZ=`lsattr -El ${TAPE} -a block_size | cut -f2 -d" "`
        VALID=true
        }

if  [ "$VALID" = "" ]
then
	echo "Tape drive $TAPE is not a valid local drive!" >&2
	exit 1
fi
}

#
# The main procedure is analogous to its C counterpart,
# This is the basic driver routine.
#
main()
{

if [ "`id | grep 'uid=0'`" = "" ]
then 
	echo "rmksysb can only be run as root!" >&2
	exit 2 
fi
umask 022

check_parms
check_host
get_tape_block_size

# display some info on this rmksysb session
echo "`date`\n\nRemote System Backup from remote ${HOST} to local `hostname` on device:\n`lscfg -v -l ${TAPE} | sed -n '3,6p' | grep "[a-z]" `\n" 

# Here the action starts
rsh $HOST -n /usr/bin/mkszfile
rsh $HOST -n "echo ${BLK_SZ} > /tapeblksz"

rsh $HOST -n "rm -f /tmp/pipe.rmksysb"
rsh $HOST -n "rm -f /tmp/pipe.rmksysb.out"
rsh $HOST -n "rm -f /tmp/pipe.rmksysb.err"

rsh $HOST -n "/etc/mknod /tmp/pipe.rmksysb p"
rsh $HOST -n "/etc/mknod /tmp/pipe.rmksysb.out p"
rsh $HOST -n "/etc/mknod /tmp/pipe.rmksysb.err p"

# create remote startup file for mkinsttape
rsh $HOST -n "echo '#!/bin/ksh\nexport PATH=$PATH ; /usr/sbin/mkinsttape /tmp/pipe.rmksysb >/tmp/pipe.rmksysb.out 2>/tmp/pipe.rmksysb.err &' > /tmp/mkinsttape.start "
rsh $HOST -n "chmod 700 /tmp/mkinsttape.start"

chdev -l $TAPE -a block_size=${BOOT_BLK_SZ} >/dev/null 2>&1
tctl -f /dev/${TAPE} retension

echo
echo
echo ">>> SAVESET 1: BOS boot image from `hostname`"
echo
bosboot -d /dev/${TAPE}.1 -a 

echo
echo
echo ">>> SAVESET 2: BOS install utilities from ${HOST} (backup format)"
echo
rsh $HOST -n "nohup /tmp/mkinsttape.start" &

# get remote standard out & err to local stdout & err
rsh $HOST -n "dd if=/tmp/pipe.rmksysb.out 2>/dev/null" | dd 2>/dev/null &
rsh $HOST -n "dd if=/tmp/pipe.rmksysb.err 2>/dev/null" | ( dd 2>/dev/null ) >&2 &

# get remote mkinsttape to local tape device
rsh $HOST -n "dd if=/tmp/pipe.rmksysb 2>/dev/null" | dd 2>/dev/null | dd of=/dev/${TAPE}.1 conv=sync 2>/dev/null

echo
echo
echo ">>> SAVESET 3: Backup information (list with ./rmksysb -l [<tapedevice>])"
echo
# add dummy TOC to tape with some backup information
echo "`date`\n\nRemote System Backup from remote ${HOST} to local `hostname` on device:\n`lscfg -v -l ${TAPE} | sed -n '3,6p' | grep "[a-z]" `\n" | dd of=/dev/${TAPE}.1 conv=sync 2>/dev/null

# change blocksize to 1024 for better performance
chdev -l ${TAPE} -a block_size=${BLK_SZ} >/dev/null 2>&1

# rewind & skip first 3 savesets
mt -f /dev/${TAPE} rewind
mt -f /dev/${TAPE}.1 fsf 3

echo
echo
echo ">>> SAVESET 4: mksysb (rootvg backup) from ${HOST} (tar format)"
echo
# start the actual remote mksysb
echo "The contents of the /.fs.size file on ${HOST} are:"
rsh $HOST -n "cat /.fs.size"
echo

rsh $HOST -n "nohup /usr/bin/mksysb /tmp/pipe.rmksysb >/tmp/pipe.rmksysb.out 2>/tmp/pipe.rmksysb.err &" &

# get remote standard out & err to local stdout
rsh $HOST -n "dd if=/tmp/pipe.rmksysb.out 2>/dev/null" | dd 2>/dev/null &
rsh $HOST -n "dd if=/tmp/pipe.rmksysb.err 2>/dev/null" | ( dd 2>/dev/null ) >&2 &
 
# get remote mksysb to local tape device
rsh $HOST -n "dd if=/tmp/pipe.rmksysb 2>/dev/null" | dd obs=${BLK_SZ} 2>/dev/null | dd of=/dev/${TAPE} bs=${BLK_SZ} conv=sync 2>/dev/null

# cleaning up
rsh $HOST -n "rm -f /tmp/pipe.rmksysb"
rsh $HOST -n "rm -f /tmp/pipe.rmksysb.out"
rsh $HOST -n "rm -f /tmp/pipe.rmksysb.err"
rsh $HOST -n "rm -f /tmp/mkinsttape.start"

chdev -l ${TAPE} -a block_size=${OLD_BLK_SZ} >/dev/null 2>&1
umask $UMASK

# display some closing info on this rmksysb session
echo "Remote System Backup from remote ${HOST} to local `hostname` is finished.\n`date`\n" 

} #end of main

# Call the driver
main 

Parent document is top of "comp.unix.aix Frequently Asked Questions (Part 5 of 5)"
Previous document is "8.06: How do I do remote backup?"
Next document is "8.07: How to configure dialup SLIP"