歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Linux下的增量備份小程序

Linux下的增量備份小程序

日期:2017/2/28 16:16:03   编辑:Linux教程

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

Copyright © Linux教程網 All Rights Reserved