Tips: 本文创建于2013年12月20日,已超过 2 年,内容或图片可能已经失效!

脚本说明:

备份脚本只备份1天之内修改的文件

恢复脚本只恢复文件,如恢复,会覆盖这一天的文件

详细请看里面的readme.txt

获得脚本:右点击图片,另存到你的电脑(要存放大后的图片)。把图片后缀名改为 .rar,解压后即可!

bak

incremental-bak备份脚本源码

#!/bin/bash  
  
# Author: liuhonghe  
# Version: 0.1  
  
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin  
export PATH  
  
# check root  
if [ $(id -u) != "0" ]; then  
    echo "Error: Must be root to run this script!"  
    exit 1  
fi  
  
# check varialbe  
cur_dir=$(pwd)  
if [ $# -eq 2 ];then  
echo "你运行的脚本是$0,你要备份的目录是$1,你要备份到$2"  
else  
echo "You can run the script like this: $0 /backupdir /tobackup"  
exit 1  
fi  
  
# run script  
find $1 -mtime -1 ! -type d > /tmp/zengliang.txt  
backup=$2  
DATE=`date +%d`  
if [ -d $backup ];then  
while read line  
do  
    cp -rf $line $backup/backup/file  
    cp /tmp/zengliang.txt $backup/backup  
done < /tmp/zengliang.txt  
cd $backup  
tar zcf backup-$DATE.tgz backup  
exit 1  
else  
clear  
echo "$backup目录不存在,创建目录中..."  
mkdir -pv $backup/backup/file  
echo "创建目录结束。"  
echo "重新执行脚本..."  
$cur_dir/$0 $1 $2  
fi  
restore恢复脚本源码  
  
#!/bin/bash  
  
# Author: liuhonghe  
# Version: 0.1  
  
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin  
export PATH  
  
# check root  
if [ $(id -u) != "0" ]; then  
    echo "Error: Must be root to run this script!"  
    exit 1  
fi  
  
# check varialbe  
if [ $# -eq 1 ];then  
echo "你运行的脚本是$0,你的压缩包在目录$1"  
else  
echo "You can run the script like this: $0 filename.tgz"  
exit 1  
fi  
  
# run script  
tardir=`dirname $1`  
tar zxf $1 -C $tardir  
cd $tardir/backup/file  
  
while read&nb
sp;line  
do  
filename=`basename $line`  
dirname=`dirname $line`  
  
if [ -d $dirname ];then  
cp -rf $filename $dirname  
else  
echo "目录$dirname不存在"  
mkdir -pv $dirname  
echo "创建$dirname成功"  
echo  
cp -rf $filename $dirname  
fi  
done < $tardir/backup/zengliang.txt