Linux: BAK_***restore.sh

#!/bin/sh
#############################################

#
# SYSTEM NAME :
# SUBSYSTEM :
# SHELL_NAME : RES_***restore.sh
# FUNCTION : restore OS image for ****
# USAGE : System Restore
# CALLED BY : NONE
# CALL TO : NONE
# RETURNS : 0=OK, 1=NG
# DESCRIPTION : restore OS image for ****
# HISTORY :
# 2009/04/29 **** FIRST RELEASE
#
#############################################

#############################################
# Enviroment :
#############################################
SYSIMAGE=”/mnt/sysimage”

#############################################
# Main :
#############################################
# tape position set to BOT
mt -f /dev/nst0 rewind
RC=$?
if [ $RC -ne 0 ]
then
echo “Failed to set tape position to BOT!! RC=$RC”
exit 1
fi

if [ $RC -eq 0 ]
then
# rebuild partition
echo “Rebuild partition.”
sfdisk /dev/sda < /tmp/sfdisk.dump
RC=$?
if [ $RC -eq 0 ]
then
# make filesystem
echo “Make filesystems.”
mke2fs -j -L / /dev/sda1
RC=$?
if [ $RC -ne 0 ]
then
echo “Make filesystem /dev/sda1 failed!! RC=$RC”
exit 1
fi
mke2fs -j -L /var /dev/sda2
RC=$?
if [ $RC -ne 0 ]
then
echo “Make filesystem /dev/sda2 failed!! RC=$RC”
exit 1
fi
mke2fs -j -L /tmp /dev/sda3
RC=$?
if [ $RC -ne 0 ]
then
echo “Make filesystem /dev/sda3 failed!! RC=$RC”
exit 1
fi
mkswap -L SWAP-sda5 /dev/sda5
RC=$?
if [ $RC -ne 0 ]
then
echo “Make swap /dev/sda5 failed!! RC=$RC”
exit 1
fi
swapon /dev/sda5

# tape position set to next point
mt -f /dev/nst0 fsf 1
RC=$?
if [ $RC -ne 0 ]
then
echo “Failed to set tape position to next point RC=$RC”
exit 1
fi
else
echo “Failed to rebuild partition !! RC=$RC”
exit 1
fi
fi

mkdir -p $SYSIMAGE

if [ $RC -eq 0 ]
then
# restore “/” partition
echo “Restore / partition.”
mount /dev/sda1 $SYSIMAGE
RC=$?
if [ $RC -ne 0 ]
then
echo “Mount /dev/sda1 partition to $SYSIMAGE failed!! RC=$RC”
else
cd $SYSIMAGE
restore -rf /dev/nst0
RC=$?
if [ $RC -ne 0 ]
then
echo “Restore / partition failed!! RC=$RC”
else
mt -f /dev/nst0 fsf 1
RC=$?
if [ $RC -ne 0 ]
then
echo “Failed to set tape position to next point RC=$RC”
fi
fi
fi
fi

if [ $RC -eq 0 ]
then
# restore “/var” partition
echo “Restore /var partition.”
mount /dev/sda2 $SYSIMAGE/var
RC=$?
if [ $RC -ne 0 ]
then
echo “Mount /dev/sda2 partition to $SYSIMAGE/var failed!! RC=$RC”
else
cd $SYSIMAGE/var
restore -rf /dev/nst0
RC=$?
if [ $RC -ne 0 ]
then
echo “Restore /var partition failed!! RC=$RC”
else
mt -f /dev/nst0 fsf 1
RC=$?
if [ $RC -ne 0 ]
then
echo “Failed to set tape position to next point RC=$RC”
fi
fi
fi
fi

if [ $RC -eq 0 ]
then
# restore “/tmp” partition
echo “Restore /tmp partition.”
mount /dev/sda3 $SYSIMAGE/approot
RC=$?
if [ $RC -ne 0 ]
then
echo “Mount /dev/sda3 partition to $SYSIMAGE/tmp failed!! RC=$RC”
else
cd $SYSIMAGE/tmp
restore -rf /dev/nst0
RC=$?
if [ $RC -ne 0 ]
then
echo “Restore /tmp partition failed!! RC=$RC”
else
mt -f /dev/nst0 fsf 1
RC=$?
if [ $RC -ne 0 ]
then
echo “Failed to set tape position to next point RC=$RC”
fi
fi
fi
fi

# Remove restoresymtable file
echo “Remove restoresymtable file”
rm -f $SYSIMAGE/restoresymtable
rm -f $SYSIMAGE/var/restoresymtable
rm -f $SYSIMAGE/tmp/restoresymtable

if [ $RC -eq 0 ]
then
# install GRUB to /dev/sda
#echo “Install GRUB to /dev/sda”
#chroot $SYSIMAGE mknod /dev/sda b 8 0
#chroot $SYSIMAGE mknod /dev/sda1 b 8 1
#chroot $SYSIMAGE umount /boot
#chroot $SYSIMAGE mount /dev/sda1 /boot
chroot $SYSIMAGE grub-install /dev/sda
RC=$?
if [ $RC -ne 0 ]
then
echo “Install GRUB to /dev/sda failed!!”
fi
fi

# unmount filesystem
cd /
echo “Unmounting /var partition”
umount $SYSIMAGE/var
echo “Unmounting /tmp partition”
umount $SYSIMAGE/tmp
echo “Unmounting / partition”
umount $SYSIMAGE

if [ $RC -ne 0 ]
then
exit 1
else
echo “Restore Finished. Please reboot.”
exit 0
fi

#############################################
### End of file

Leave a Comment

Your email address will not be published. Required fields are marked *

CAPTCHA * Time limit is exhausted. Please reload the CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top