• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

自动进行system disk clone 的 shell script (原创)

发布: 2007-6-08 22:43 | 作者: seanhe | 来源: | 查看: 19次 | 进入软件测试论坛讨论

领测软件测试网
看到大家讨论好多system clone  的帖子,结合自己的实际写了这么一个script, 自动进行disk clone, 适用与4.0x的ufs 或advfs,
在我的DS10上运行通过。

大家有什么批评和建议,请不吝赐教


testbackup :

#!/bin/sh
# This script performs a disk-to-disk clone for backing up LMC alphastation DS10 system
# disks running either 4.0D or 4.0G
# Usage : # testbackup
# Author : Qing Zhu
# Date : Mar 19, 2004

echo
echo "***** System backup procedure invoked *******"
echo

# version check
echo -n "Checking OS version ...     "
version=`sizer -v |awk '{print $3}'`
echo "done"

# Check device name of the system disk
echo -n "Checking current system disk ...     "
if [ "$version" = "V4.0D" ]; then
current_hd=`df | grep -w "\/" | cut -c6-8`
fi
if [ "$version" = "V4.0G" ]; then
current_hd=`ls -al /etc/fdmns/root_domain | awk '{print $9}'|cut -c1-3`
fi
current_hd_c=$current_hd"c"
current_hd_a=$current_hd"a"
current_hd_b=$current_hd"b"
current_hd_g=$current_hd"g"
echo "done"

# User input device name of the new disk
echo
echo "Please enter the device name of the new disk, e.g. \"rz2\" where 2 is"
echo -n "the scsi id of the new disk: "
read new_hd
new_hd_c=$new_hd"c"
new_hd_a=$new_hd"a"
new_hd_b=$new_hd"b"
new_hd_g=$new_hd"g"

echo
echo -n "Clearing disklabel on the new disk $new_hd ...     "
disklabel -z $new_hd >/dev/null 2>&1
echo "done"
echo
echo "Dumpping filesystem from system disk $current_hd_c to new disk $new_hd_c"
echo -n "this may take more than half an hour depend on the size of the filesystem " 
dd if=/dev/$current_hd_c of=/dev/$new_hd_c conv=noerror,sync bs=512k &

# waiting dots, a little decoration
id=$!
while ps ax | grep "^[[:space:]]*$id" > /dev/null
do
echo -n "."
sleep 5
done

#if [ $? != 0 ]; then
# echo "Dump error, exit"
# exit 2
#fi
echo 
echo "Dump completed"

echo
echo "Checking file integrity of the new disk ..."
echo -n "Checking partition a ..."
fsck /dev/$new_hd_a
echo 
echo -n "Checking partition g ..."
fsck /dev/$new_hd_g
echo

echo
echo -n "Changing fstab and swapdefault ...     "
umount /mnt >/dev/null 2>&1
mount -t ufs /dev/$new_hd_a /mnt
if [ $? != 0 ]; then 
echo "Mount error, exit"
exit 2
fi

if [ "$version" = "V4.0D" ]; then
cd /mnt/etc
#cat fstab
cp fstab fstab.sav
#cat fstab | sed -e 's/rz0a/rz2a/' -e 's/rz0g/rz2g/' -e 's/rz0b/rz2b/g' > temp
cat fstab | sed 's/rz0/'$new_hd'/g' > temp
mv temp fstab
cd /mnt/sbin
rm swapdefault
ln -s /dev/$new_hd_b swapdefault
fi
if [ "$version" = "v4.0G" ]; then
cd /mnt/etc
cp fstab fstab.sav
cat fstab | sed 's/rz0/'$new_hd'/g' > fstab
cd /mnt/etc/fdmns/root_domain
ln -fs /dev/$new_hd_a $new_hd_a
cd /mnt/etc/fdmns/usr_domain
ln -fs /dev/$new_hd_g $new_hd_g
cd /mnt/sbin
rm swapdefault
ln -s /dev/$new_hd_b swapdefault
fi

cd /
umount /mnt
echo "done"

echo 
echo
echo "Now please issue the command \"shutdown -h now\" to halt the system and then"
echo "type \"b dka???\" under >>> console prompt to boot from the clonned disk,"
echo "where ??? can be determined by \"show dev\". Should the reboot be successful,"
echo "the old disk can be safely removed."
echo

 我爱臭豆腐 回复于:2004-03-21 07:19:56
:em27: 好给你加为了精华。希望以后能够有更多的好帖子

延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网