Linux: BAK_***backup.sh

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

# SYSTEM NAME :
# SUBSYSTEM :
# SHELL_NAME : BAK_***backup.sh
# FUNCTION : backup OS image for ****
# USAGE : SYSTEM Backup
# CALLED BY : NONE
# CALL TO : NONE
# RETURNS : 0=OK, 1=NG
# DESCRIPTION : backup OS image for ****
# HISTORY :
# 2009/04/10 **** FIRST RELEASE
#
##########################################

##########################################
# Enviroment :
##########################################
# /dev/sda1 = /
# /dev/sda2 = /var
# /dev/sda3 = /tmp
# /dev/sda5 = swap
##########################################
BK_PART=”/dev/sda1 /dev/sda2 /dev/sda3″

##########################################
# 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

# copy /etc/fstab
if [ $RC -eq 0 ]
then

mkdir -p /mnt/sda1
mount /dev/sda1 /mnt/sda1
RC=$?
if [ $RC -ne 0 ]
then
echo “Mount /dev/sda1 partition to /mnt/sda1 failed!! RC=$RC”
fi
cp -p /mnt/sda1/etc/fstab /etc/fstab
RC=$?
if [ $RC -ne 0 ]
then
echo “Copy /etc/fstab failed!! RC=$RC”
fi
umount /mnt/sda1
fi

# getting partition-info and backup partition-info & restore shell.
if [ $RC -eq 0 ]
then
sfdisk -d /dev/sda > /tmp/sfdisk.dump
RC=$?
if [ $RC -eq 0 ]
then
#mkdir -p /mnt/sda1
mount /dev/sda1 /mnt/sda1
RC=$?
if [ $RC -ne 0 ]
then
echo “Mount /dev/sda1 partition to /mnt/sda1 failed!! RC=$RC”
exit 1
fi
cp -p /mnt/sda1/acom/***/bin/backup/BAK_***restore.sh /tmp
RC=$?
if [ $RC -eq 0 ]
then
cd /tmp
tar -cf /dev/nst0 sfdisk.dump BAK_***restore.sh
RC=$?
if [ $RC -ne 0 ]
then
echo “getting tar image for /tmp failed!! RC=$RC”
fi
else
echo “Copy restore shell failed!! RC=$RC”
fi
umount /mnt/sda1
#rmdir /mnt/sda1
else
echo “getting partition info failed!! RC=$RC”
exit 1
fi
fi

# getting dump images
if [ $RC -eq 0 ]
then
for part in $BK_PART
do
echo “getting dump image for $part”
dump -uf /dev/nst0 $part
RC=$?
if [ $RC -ne 0 ]
then
echo “getting dump image for $part failed!! RC=$RC”
break
fi
echo “finished getting dump image for $part”
done
fi

mt -f /dev/nst0 rewind
RC=$?
if [ $RC -ne 0 ]
then
echo “Warning : Failed to set tape position to BOT!!(RC=$RC). check tape condition.”
RC=0
fi

# add dumpdates to /etc/dumpdates
if [ $RC -eq 0 ]
then

mount /dev/sda1 /mnt/sda1
RC=$?
if [ $RC -ne 0 ]
then
echo “Mount /dev/sda1 partition to /mnt/sda1 failed!! RC=$RC”
fi
cat /etc/dumpdates >> /mnt/sda3/etc/dumpdates
umount /mnt/sda1
rmdir /mnt/sda1
fi

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

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

Leave a Reply

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.