Article View: alt.os.linux.suse
Article #209Re: how to copy hda to hdb?
From: alex
Date: Wed, 14 Nov 2001 20:45
Date: Wed, 14 Nov 2001 20:45
314 lines
11666 bytes
11666 bytes
look at this :-) hardcore - but for solaris... anyone able to tell me what
need to be changed for suse 7.2?
Alex
#!/bin/sh
######################################################################
#
# COMPONENT NAME: diskcopy.sh
#
# AUTHOR: Carsten Dewitt
# COMPANY: m+s Elektronik AG
# VERSION: 01.08.09 (date)
#
# Last version from : Angel Gomez (ENS)
#
# FUNCTION: Makes a complete copy from one hardisk to the other
# These Harddisks are supposed to be two EIDE HDD
# connected to controller 0 of an ULTRA 10
# (c0t0d0sX and c0t1d0sX)
#
# OS LEVEL SUPPORT: Solaris 8
# PARAMETERS: none
#
# LOGFILE: /var/log/boerse/diskcopy.log
#
# EXAMPLE:
#
# CHANGES: 04.06.99 CD Creation
# 26.01.00 CD Released
# 29.03.00 CD Added the disk check part
# 29.03.00 CD Added the DISK0/DISK1 check stuff
# 30.03.00 CD Debuged
# 31.03.00 CD Simplified the fsck part
# 07.04.00 CD Changed the date format
# 11.04.00 CD Added the fsck try for three times part
# 11.04.00 CD Improved the format of the log-file entries
# 11.04.00 CD Added the check if /mnt is mounted part
# 11.04.00 CD Improved the check of current HDD
# 11.04.00 CD Added exit status to be used with PatrolAgent
# 17.04.00 CD Changed to be used for the finally agent setup
# 18.04.00 CD Added the error code 40 part for fsck
# 09.08.01 AG (by Angel Gomez - ENS)
# Changes for SOLARIS 8
# Works now with different disks sizes
#
######################################################################
######################################################################
# Variable definition
######################################################################
DATE=`date '+%b %e %H:%M:%S'`
DATE_FILE=`date '+%m%d%y%H%M'`
SCRIPT=diskcopy.sh
LOGPATH=/var/log/
LOGFILE=diskcopy.log
HOSTNAME=`hostname`
RAW=/dev/rdsk/ # to create the raw device names
BLOCK=/dev/dsk/ # to create the block device names
S0=s0 # slice 0 (/)
S2=s2 # slice 2 (backup)
LOOP=1 # To try the fsck for three times
DO_DD=true # to verify that dd can be really started
######################################################################
# Check if the log path and log file exists, if not create it
######################################################################
if (test -d $LOGPATH)
then
cd $LOGPATH
if (test -s $LOGFILE)
then
cp $LOGFILE $LOGFILE.$DATE_FILE # copy old log file
cat /dev/null > $LOGFILE # empty log file
else
touch $LOGPATH$LOGFILE # create log file
fi
else
mkdir $LOGPATH
touch $LOGPATH$LOGFILE
fi
######################################################################
# Creating the header of the log file
######################################################################
echo "***************************************************" >>
$LOGPATH$LOGFILE
echo "Logfile created by $SCRIPT at $DATE" >> $LOGPATH$LOGFILE
echo "This is machine: $HOSTNAME" >> $LOGPATH$LOGFILE
echo "***************************************************" >>
$LOGPATH$LOGFILE
######################################################################
# Make sure nothing is mounted onto /mnt
######################################################################
cat /dev/null > /tmp/mount.check # Make sure the check file is empty
cat /etc/mnttab | grep /mnt > /tmp/mount.check # Check if /mnt is in use, if
so unmount it
if (test -s /tmp/mount.check)
then
echo "$DATE $HOSTNAME $SCRIPT: information: /mnt is currently in use try to
unmount:" >> $LOGPATH$LOGFILE
umount /mnt 2>> $LOGPATH$LOGFILE > /dev/null
EXIT=`echo $?`
if (test $EXIT = "0")
then
echo "$DATE $HOSTNAME $SCRIPT: information: unmount of /mnt was
successfull" >> $LOGPATH$LOGFILE
else
echo "$DATE $HOSTNAME $SCRIPT: error: unmount of /mnt was NOT successfull"
>> $LOGPATH$LOGFILE
fi
fi
rm /tmp/mount.check # Removing temporary file
######################################################################
# First of all we need to check on which HDD we are on
######################################################################
cat /dev/null > /tmp/disk0.check # Make sure the check file is empty
cat /dev/null > /tmp/disk1.check # Make sure the check file is empty
df -k | grep c0t0d0 > /tmp/disk0.check # Check if we are on disk0
df -k | grep c0t1d0 > /tmp/disk1.check # Check that only disk0 is used
if (test -s /tmp/disk1.check)
then
DISK_SRC=c0t1d0 # define the source disk
DISK_DEST=c0t0d0 # define the destination disk
VFS_END=hd0 # define the ending of the vfstab to be copied onto destination
disk
else
if (test -s /tmp/disk0.check)
then
DISK_SRC=c0t0d0 # define the source disk
DISK_DEST=c0t1d0 # define the destination disk
VFS_END=hd1 # define the ending of the vfstab to be copied onto
destination disk
fi
fi
if ((test -s /tmp/disk0.check) && (test -s /tmp/disk1.check))
then
echo "$DATE $HOSTNAME $SCRIPT: error: Could not terminate on which harddisk
the script was started" >> $LOGPATH$LOGFILE
DO_DD=false
fi
rm /tmp/disk0.check # Removing temporary file
rm /tmp/disk1.check # Removing temporary file
######################################################################
# Check the disk which is currently in use
######################################################################
if (test $DO_DD = "true") # Just start the whole stuff, if everything has
been correct so far
then
for S1 in s0 s4 s5
do
LOOP=1
while (test $LOOP -lt 4)
do
fsck -y $RAW$DISK_SRC$S1 2>> $LOGPATH$LOGFILE > /dev/null # check slice 1
of source disk
EXIT=`echo $?`
if ((test $EXIT = "0") || (test $EXIT = "40"))
then
DATE=`date '+%b %e %H:%M:%S'`
echo "$DATE $HOSTNAME $SCRIPT: information: Filesystem of
$RAW$DISK_SRC$S1 is ok" >> $LOGPATH$LOGFILE
LOOP=4
if (test $DO_DD = "true")
then
DO_DD=true
else
DO_DD=false
fi
else
DATE=`date '+%b %e %H:%M:%S'`
echo "$DATE $HOSTNAME $SCRIPT: information: Trying to check
$RAW$DISK_SRC$S1 for the $LOOP. time" >> $LOGPATH$LOGFILE
echo "$DATE $HOSTNAME $SCRIPT: warning: Filesystem of $RAW$DISK_SRC$S1
needs maintenance" >> $LOGPATH$LOGFILE
LOOP=`expr $LOOP + 1`
DO_DD=false
fi
done
done
######################################################################
# Starting the diskcopy using dd
######################################################################
if (test $DO_DD = "true") # Just make a copy if the filesystem check of the
source disk is ok
then
for S1 in s0 s4 s5
do
echo "$DATE $HOSTNAME $SCRIPT: information: Started dd for $S1" >>
$LOGPATH$LOGFILE
echo "$DATE $HOSTNAME $SCRIPT: information: Output of dd for $S1:" >>
$LOGPATH$LOGFILE
dd if=$RAW$DISK_SRC$S1 of=$RAW$DISK_DEST$S1 bs=144b 2>> $LOGPATH$LOGFILE
EXIT=`echo $?`
DATE=`date '+%b %e %H:%M:%S'`
echo "$DATE $HOSTNAME $SCRIPT: information: Ended dd" >> $LOGPATH$LOGFILE
if (test $EXIT = "0")
then
echo "$DATE $HOSTNAME $SCRIPT: information: The creation of the
HDD image ($DISK_SRC$S1 --> $DISK_DEST$S1) ended successfull " >>
$LOGPATH$LOGFILE
else
echo "$DATE $HOSTNAME $SCRIPT: error: The creation of the HDD
image ($DISK_SCR$S1 --> $DISK_DEST$S1) was NOT successfull " >>
$LOGPATH$LOGFILE
fi
done
######################################################################
# Checking the filesystems of the copied HDD
######################################################################
for S1 in s0 s4 s5
do
fsck -y $RAW$DISK_DEST$S1 2>> $LOGPATH$LOGFILE > /dev/null # Check slice
1 of destination disk
EXIT=`echo $?`
if ((test $EXIT = "0") || (test $EXIT = "40"))
then
DATE=`date '+%b %e %H:%M:%S'`
echo "$DATE $HOSTNAME $SCRIPT: information: Filesystem of
$RAW$DISK_DEST$S1 is ok" >> $LOGPATH$LOGFILE
else
DATE=`date '+%b %e %H:%M:%S'`
echo "$DATE $HOSTNAME $SCRIPT: warning: Filesystem of $RAW$DISK_DEST$S1
needs maintenance" >> $LOGPATH$LOGFILE
fi
done
######################################################################
# Motifying the vfstab
######################################################################
fsck -y $RAW$DISK_DEST$S0 2>> $LOGPATH$LOGFILE > /dev/null
mount $BLOCK$DISK_DEST$S0 /mnt 2>> $LOGPATH$LOGFILE > /dev/null
cp /etc/vfstab.$VFS_END /mnt/etc/vfstab 2>> $LOGPATH$LOGFILE > /dev/null
EXIT=`echo $?`
DATE=`date '+%b %e %H:%M:%S'`
if (test $EXIT = "0")
then
echo "$DATE $HOSTNAME $SCRIPT: information: Successfully copied
vfstab.$VFS_END" >> $LOGPATH$LOGFILE
else
echo "$DATE $HOSTNAME $SCRIPT: warning: Could not copy
vfstab.$VFS_END" >> $LOGPATH$LOGFILE
fi
umount /mnt 2>> $LOGPATH$LOGFILE > /dev/null
######################################################################
# Verifying the vfstab
######################################################################
cat /dev/null > /tmp/vfstab.check # Make sure the check file is empty
fsck -y $RAW$DISK_DEST$S0 2>> $LOGPATH$LOGFILE > /dev/null
mount $BLOCK$DISK_DEST$S0 /mnt 2>> $LOGPATH$LOGFILE > /dev/null
cat /mnt/etc/vfstab | grep $DISK_DEST > /tmp/vfstab.check
DATE=`date '+%b %e %H:%M:%S'`
if (test -s /tmp/vfstab.check)
then
echo "$DATE $HOSTNAME $SCRIPT: information: vfstab of $DISK_DEST is ok!"
>> $LOGPATH$LOGFILE
else
echo "$DATE $HOSTNAME $SCRIPT: error: vfstab of $DISK_DEST is not the
correct version!" >> $LOGPATH$LOGFILE
fi
umount /mnt 2>> $LOGPATH$LOGFILE > /dev/null
rm /tmp/vfstab.check
exit 0
else
DATE=`date '+%b %e %H:%M:%S'`
echo "$DATE $HOSTNAME $SCRIPT: error: Could not make the disk copy, due
problems with the filesystem" >> $LOGPATH$LOGFILE
exit 1
fi
else
echo "$DATE $HOSTNAME $SCRIPT: error: Could not make the disk copy, due to
errors" >> $LOGPATH$LOGFILE
exit 1
fi
DATE=`date '+%b %e %H:%M:%S'`
echo "*****************************************************************" >>
$LOGPATH$LOGFILE
echo "script ended at $DATE" >> $LOGPATH$LOGFILE
echo "*****************************************************************" >>
$LOGPATH$LOGFILE
######################################################################
# End of script
######################################################################
Technical Details
Message-ID:
<9sul4v$g1n$00$1@news.t-online.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!dispose.news.demon.net!demon!diablo.theplanet.net!newsfeed00.sul.t-online.de!newsmm00.sul.t-online.com!t-online.de!news.t-online.com!not-for-mailReferences:
<9stg5i$ujh$05$1@news.t-online.com> <uu3us9.e48.ln@semis.de>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1041dd,783babf71ea1bc64 X-Google-Attributes: gid1041dd,public X-Google-Thread: f4b73,783babf71ea1bc64 X-Google-Attributes: gidf4b73,public X-Google-ArrivalTime: 2001-11-14 12:46:08 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!dispose.news.demon.net!demon!diablo.theplanet.net!newsfeed00.sul.t-online.de!newsmm00.sul.t-online.com!t-online.de!news.t-online.com!not-for-mail From: "alex" <ntnewsNOSPAM@hrz3.hrz.tu-darmstadt.de> Newsgroups: alt.os.linux.suse,ch.comp.os.linux Subject: Re: how to copy hda to hdb? Date: Wed, 14 Nov 2001 21:45:03 +0100 Organization: T-Online Lines: 317 Message-ID: <9sul4v$g1n$00$1@news.t-online.com> References: <9stg5i$ujh$05$1@news.t-online.com> <uu3us9.e48.ln@semis.de> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: news.t-online.com 1005770720 00 16439 CzYvT3ZESzArMl 011114 20:45:20 X-Complaints-To: abuse@t-online.com X-Sender: 520078324419-0001@t-dialin.net X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000