|

楼主 |
发表于 2009-4-4 11:39:41
|
显示全部楼层
求天,求地,求人,不如求自己。本着“自己动手,丰衣足食”的原则。写了以下的这个脚本。主要实现功能是第一次运行该脚本时,产生一个“基准”备份点,以后每次运行这个脚本时都会跟这个“基准”点比较,实现增量,差异,“减量”备份。当然也可以稍作修改,使之每次备份是跟上一次对比。
#!/bin/sh
#yum clean all
backupdir="/bt/test"
if [ ! $1 == "" ];then
destdir=$1
else
destdir="/media/DATA_5/"
fi
echo "Save Partition :"$destdir
echo "Now , backup system .........>>>>>>>"
if [ -d $destdir ] ;then
# destdir="/media/DATA2/"
diskfree=`df -h $destdir |grep dev |sed -e 's/[[:space:]][[:space:]]*/ /g'|cut -d' ' -f4|cut -d'G' -f1`
echo "Target Disk $destdir has "$diskfree"G free"
diskfree=`echo "$diskfree*10" |bc |cut -d"." -f1`
#echo "diskfree"$diskfree
if [ $diskfree -gt "43" ];then
tree $backupdir -f -I "mnt|proc|media|home|root|btdown|tmp|sys|dev|tmp|squid|clientmqueue" -o "$destdir"tree.txt
if [ -f "$destdir"snapshot.org ];then
cp "$destdir"snapshot.org "$destdir"snapshot
diff "$destdir"tree.txt "$destdir"tree.txt.org >"$destdir"diff.txt
tar -g "$destdir"snapshot -jcf "$destdir"fc9_backup_inc.tar.bz2 $backupdir --exclude=/mnt/* --exclude=/proc/* --exclude=/media/* --exclude=/home/* --exclude=/root/* --exclude=/btdown/* --exclude=/tmp/* --exclude=/sys/* --exclude=/dev/* --exclude=/var/tmp/* --exclude=/var/spool/squid/* --exclude=/var/spool/clientmqueue/*
#--exclude=/var/log/*.* --exclude=/var/cache/*
else
tar -g "$destdir"snapshot -jcf "$destdir"fc9_backup.tar.bz2 $backupdir --exclude=/mnt/* --exclude=/proc/* --exclude=/media/* --exclude=/home/* --exclude=/root/* --exclude=/btdown/* --exclude=/tmp/* --exclude=/sys/* --exclude=/dev/* --exclude=/var/tmp/* --exclude=/var/spool/squid/* --exclude=/var/spool/clientmqueue/*
#--exclude=/var/log/*.* --exclude=/var/cache/*
cp "$destdir"snapshot "$destdir"snapshot.org
cp "$destdir"tree.txt "$destdir"tree.txt.org
echo "slite the gz file to rar ........>>>"
cd $destdir
rar a -m0 -v920m fc9_bkg.rar fc9_backup.tar.bz2
fi
echo "finish.......<>>"
else
echo "Disk not Enough...."
fi
else
echo "$destdir is not an available directory.."
fi |
|