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

Unix/Linux
Linux系统下如何监视系统资源使用率
怎样在Red Hat Linux上使用BIND建立DNS服务器
多点触控技术终于在Linux中实现
中科红旗Linux桌面7.0版引入QtSDK组件
系统启动管理器与GRUB
Linux系统下配置CVS集成cvstrac
解析Linux操作系统下usr的目录结构
Linux系统与Windows系统的线程有何不同
黑客怎样入侵Linux系统
维护inittab配置文件时需要注意的事项
FreeBSD为powerd设置cpu最小工作频率
如何配置Linux才能保证其系统的安全
光驱的软开关与限速简介
新手教程之创建锁文件的方法
双系统计算机怎样卸载其中一个?
运行Linux时的快捷键使用
phpMyAdmin安装方法及介绍
Wine中中文存在很多的乱码怎么解决?
Linux教程:tail命令的巧妙应用
Wget命令来浏览网页的方法

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


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