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

Unix/Linux
通过管理工具自建Linux防火墙
Linux系统下挂载Windows分区的方法
Linux下使用Mplayer播放各种格式的电影
Linux系统下的硬件安装
Linux系统下的软件安装
Linux系统如何显示多核模式
利用变量在Linux中给文件命名
Linux操作系统中的七件独门武器
如何更有效优化Linux系统硬盘
解决Linux系统无法开机的问题
教你生成Linux系统下Makefile的automake
11正式发布-基于Linux操作系统 Fedora
发布Linux Kernel内核最新稳定版2.6.30
推荐六款高品质免费Linux CAD应用程序
Linux操作系统下运行命令时CTRL+Z的作用
教你Linux系统下配置双网卡路由表
教你在Linux中验证SMB网络协议
Linux系统中确保访问三级域名畅通的方法
linux操作系统的crontab定时命令
Linux系统:特权帐号VS普通帐号

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-01   浏览: 53 ::
收藏到网摘: 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 ##