备份一个Linux系统硬盘 II

<备份一个Linux系统硬盘 I>解决了第一次系统克隆问题,可是随着原系统的运行和发展,这两个硬盘的内容的差距也会越来越大。我们可以每天在低峰访问时间,比如半夜2点,同步一个备份硬盘和原系统。

#! /bin/sh # sync backup system # written by Visual.Wei rootdirlist=`ls /` skiplist="boot dev mnt proc sys" bskip="0" mirrordsk=/dev/sdb mntpoint=/mnt/mybakroot makedir() { if [ ! -d $1 ] ; then echo $"create directory $1" mkdir -p $1 else echo $"dir $1 already existing" fi } umnt() { if [ -e /proc/mounts ] ; then if grep $1 /proc/mounts > /dev/null ; then umount $1 echo $"unmount device $1" fi fi } checkdisk() { if [ ! -e $1 ] ; then echo "Mirror Device $1 can not be found" return 1 else return 0 fi } if ! checkdisk "$mirrordsk" ; then exit 1 fi umnt "$mirrordsk"1 umnt "$mirrordsk"5 umnt "$mirrordsk"6 umnt "$mirrordsk"3 makedir $mntpoint echo $"mount directories" mount "$mirrordsk"3 $mntpoint mount "$mirrordsk"5 $mntpoint/var mount "$mirrordsk"6 $mntpoint/home echo $"Sync system directories...It may takes very long time" for i in $rootdirlist ; do bskip="0" for j in $skiplist ; do if [ "$i" == "$j" ] ; then echo $"skip sync: $i" bskip="1" break fi done if [ "$bskip" == "0" ] ; then echo $"---> Sync directory: $i" time rsync -av /$i/ $mntpoint/$i/ fi done umnt "$mirrordsk"1 umnt "$mirrordsk"5 umnt "$mirrordsk"6 umnt "$mirrordsk"3 sync echo $"Power Down $mirrordsk" /sbin/hdparm -y $mirrordsk > /dev/null

你可能感兴趣的:(linux,System)