红联Linux门户
Linux帮助

Linux下的增量备份小程序

发布时间:2015-01-29 15:30:10来源:linux网站作者:a199001180

Linux下增量备份程序的命令形式:

1.可执行文件 源文件 as:./a  sourcefile

2. 更新备份的时间:usage as:1979-01-01 10:20 : 1979 01 01 10 20

3.输入增量备份的目文件:

#获取文件的更新时间

function gettime(){

var=`ls -l $1| grep ":[0-9]\{2,\} 1" | sed 's/[ ]\{1,\}/ /g' | cut -f6-7  -d' ' | sed 's/[ -:]//g'`

echo $var

}

#对文件进行增量备份

function getdir(){

for name in `ls $1`

do

if [ -d $1"/"$name ]; then

mkdir -p $localname"/"$1"/"$name

getdir $1"/"$name

else

new_time=`gettime $1"/"$name`

if [ $new_time -ge $time ]; then

#通过增量备份时间与文件更新时间的差值对比,来确定是否进行备份

cp $1"/"$name -t $localname"/"$1"/"

fi

fi

done

}

printf "Please enter the date,time :(as:1979-01-01 10:20 : 1979 01 01 10 20)\n"

read time1 time2 time3 time4 time5

#获取增量备份时间

time="$time1$time2$time3$time4$time5"

#read time1 time2

#time="$time1$time2"

#echo $time

printf "Please enter the direction name:"

#增量备份所存文件夹

read localname

mkdir -p $localname"/"$1

getdir $1