当前位置: 首页 > 图文教程 > 操作系统 > Unix/Linux > 脚本欣赏----Shell Script to Clone Linux System - 20041201

Unix/Linux
Linux网管123---组态XWindow系统-1.使用X-Configurator
Linux网管123---安装及硬体组态-8.下载及安装RedHat更新程式
Linux网管123---安装及硬体组态-7.从LILO启动
Linux网管123---安装及硬体组态-1.建立一张安装磁片
Linux程式设计-11.ShellScript(bash)--(2)教学例
Linux程式设计-11.ShellScript(bash)--(1)简介
简单配置linux下的网络邻居samba
如何使用 Linux 系统下的编辑器系列教程(1)
如何将.tif\.rgb\.gif......的图片转换成.xpm的格式?
请问linux下如何查看打开的文件数?谢谢如bsd下面的pstat -T
Redhat 8.0运行一段时间就死机高手帮忙啊(重发)
filesystem type unknown
LINUX与UNIX SHELL编程指南 下载
LINUX应用程序开发指南 下载
各位大哥,请告诉我linux下的文件目录的颜色代表什么?
安装最新中文OpenOffice.org 1.1 RC3
关于redhat 9.0 打开进程打开最大文件数
如何在shell脚本程序中获取日期值?
关于dd命令的求助!!!
如何恢复grub?

Unix/Linux 中的 脚本欣赏----Shell Script to Clone Linux System - 20041201


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-01   浏览: 72 ::
收藏到网摘: n/a

From: http://www.yick.org/website/index.php?module=documents&JAS_DocumentManager_op=viewDocument&JAS_Document_id=12 代码:#!/bin/sh # Desc: Dump and Restore Disk using dump and restore commands # Author: Swergar
脚本欣赏----Shell Script to Clone Linux System - 20041201From: http://www.yick.org/website/index.php?module=documents&JAS_DocumentManager_op=viewDocument&JAS_Document_id=12 代码:#!/bin/sh # Desc: Dump and Restore Disk using dump and restore commands # Author: Swergar # # *** Please read the bottom of this script for Help *** # ## Configurations # which dir to store backup files? #BACKDIR="/mnt/ghost/`hostname -s`" BACKDIR="/opt/backup" # which dir to store backup files? #BACKDIR="/mnt/ghost/test" # which dir/files want to exclude? EXCLUDE="/var/log /var/spool/mail /opt/config_backup $BACKDIR" # define these values for raid system PHYDISK=hda MIRRORDISK=hdb ################################################################################ # Detect raid ISRAID=`grep `df / | grep ^/dev| cut -d " " -f 1 | sed 's//dev///g'` /proc/mdstat | grep -c md` if [ "$ISRAID" -gt "0" ] ; then RAIDDEVICE="yes" ; MD=`df / | grep ^/dev| cut -d " " -f 1 | sed 's//dev///g'| sed 's/[0-9]//g'` DUMPPRTS=`df | grep ^/dev/$MD | sed 's/ */ /g'| cut -d " " -f 6| grep -v "^/$" ` rm -f /tmp/fstab.raid /tmp/df.txt RAID=`cat /proc/mdstat | grep ^md| cut -d " " -f 1,5| tr " " ":" | sed 's/[[0-9]]//g'` for i in $RAID ; do HRD=`echo $i | cut -d ":" -f 1` HDEV=`echo $i | cut -d ":" -f 2| sed 's/[a-z]//g'` HDEV=$PHYDISK$HDEV cat /etc/fstab | grep $HRD | sed s/$HRD/$HDEV/ >> /tmp/fstab.raid df -m -l -T --sync | grep $HRD | sed s/$HRD/$HDEV/ >> /tmp/df.txt done FSTAB="/tmp/fstab.raid" DF="cat /tmp/df.txt" else RAIDDEVICE="no"; FSTAB="/etc/fstab" DF="df -m -l -T --sync" PHYDISK=`df / | grep ^/dev| cut -d " " -f 1 | sed 's//dev///g'| sed 's/[0-9]//g'` DUMPPRTS=`df | grep ^/dev/$PHYDISK | sed 's/ */ /g'| cut -d " " -f 6| grep -v "^/$"` fi if [ "$RAIDDEVICE" == "" -o "$PHYDISK" == "" -o "$DUMPPRTS" == "" ] ; then echo "$RAIDDEVICE,$PHYDISK,$DUMPPRTS" echo "#Some Variables are not defined" echo exit 1 fi if [ ! -d "$BACKDIR" ] ; then echo echo "#*** Backup dir '$BACKDIR' does not exist!!!" echo exit 1 fi which parted > /dev/null 2>&1 if [ $? != "0" ] ; then echo "#parted not found, exit!" echo exit 1 fi which dump > /dev/null 2>&1 if [ $? != "0" ] ; then echo "#dump not found, exit!" echo exit 1 fi which stat > /dev/null 2>&1 if [ $? != "0" ] ; then echo "#stat tool not found, unset EXCLUDE" sleep 3 EXCLUDE="" fi PARTS=`/sbin/parted /dev/$PHYDISK p | grep ^[0-9] | sed 's/ext3/ext2/g' | sed 's/, /,/g' |grep ^[0-9]| sed 's/ */:/g'` if [ $? != "0" ] ; then echo "#***Error in clone partition table!!!" sleep 3 echo exit 1 fi rm -f $BACKDIR/partitions.sh for j in $PARTS ; do MIRROR=`echo $j | cut -d ":" -f 1` PSTART=`echo $j | cut -d ":" -f 2` PEND=`echo $j | cut -d ":" -f 3` TYPE=`echo $j | cut -d ":" -f 4` FS=`echo $j | cut -d ":" -f 5` FLAG=`echo $j | cut -d ":" -f 6` echo "parted -s /dev/$PHYDISK rm $MIRROR" >> $BACKDIR/partitions.sh if [ "$TYPE" != "extended" ] ; then echo "parted -s /dev/$PHYDISK mkpart $TYPE $FS $PSTART $PEND" >> $BACKDIR/partitions.sh else echo "parted -s /dev/$PHYDISK mkpart $TYPE $PSTART $PEND" >> $BACKDIR/partitions.sh fi if [ `echo $FLAG|grep -ci boot ` == 1 ] ; then echo "parted -s /dev/$PHYDISK set $MIRROR boot on" >> $BACKDIR/partitions.sh fi if [ `echo $FLAG|grep -ci raid ` == 1 ] ; then echo "parted -s /dev/$PHYDISK set $MIRROR raid on" >> $BACKDIR/partitions.sh fi done ##