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

Unix/Linux
ubuntu与windows远程连接的方法
在Ubuntu系统中文件进行加密传输
Unix 操作系统中处理字符串问题的简单方式
UNIX 操作系统复杂的关机过程
fedora phpMyAdmin 安装方法及介绍
Red Hat Enterprise Linux 4+Nginx 0.7.47+PHP5.2+MYSQL5.0+Memcache+eAccelerator收
CENTOS 系统的配置
CentOS 挂载NTFS分区的两种方法
CentOS Tomcat 的启动服务脚本
Centos5.2配置LAMP与Centos5.3配置LAMP
从技术产品市场角度阐述Linux操作系统的发展
rar for linux程序基本命令
LIDS功能:建立一个安全的Linux系统
如何来清除Linux系统命令的历史记录

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


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