`
wenhai_zhang
  • 浏览: 181081 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

linux下的文件备份(未完待续)

 
阅读更多

#/usr/bin/bsh

path_file_list="/home/zwh/backup/"
fn_file_list="$path_file_list/file_list"
fn_file_list_tmp="$path_file_list/file_list_tmp"
fn_md5_file_list="$path_file_list/md5_list"

#替换配置路径中的日期格式
replace_date()
{
$file=$1
cat $file | while read line
do
if [ ]; then
day=`echo "$path" | awk -F"%" '{print $1;}'`
day=`date %Y%m%d -d '-$day day'`
path=`echo "$path" | sed s/%YMD-\d+%/$day/ `
fi

echo "$path" >> $newconf
done
}

#替换软链接文件
replace_symbolic_link()
{
input_path=$1
output_path=$2
find "$input_path" -type l -exec file '{}' \; | awk -F": symbolic link to \`" '{ if( match("^/*$",$2) ==0 ){print $2;} }' >> "$output_path"
}

create_file_list()
{
path_tmp="$fn_file_list_tmp".tmp

# 获取所有文件列表
find "$path_file_list" -type f > "$path_tmp"

# 获取所有软链接文件列表
replace_symbolic_link "$path_file_list" "$path_tmp"

# 排序
cat "$path_tmp" | sort > "$fn_file_list_tmp"
rm -f "$path_tmp"

# 生成MD5值
cat "$fn_file_list_tmp" | xargs md5sum >> "$fn_md5_file_list"

}


repalce_date $1

分享到:
评论
1 楼 wenhai_zhang 2012-09-10  

# replace date format for "%YMD-$days%" in path.
replace_date_old()
{
    input_file=$1
    output_file=$2
    cat $input_file | while read line
    do
        if [ "$line" != "${line/"%YMD-"/}" ]; then
           
            days=`echo "${line##*%YMD-}" | awk -F"%" '{print $1}'`
            day=`date +%Y%m%d -d ''-$days' day'`
            line=`echo $line | sed s/%YMD-$days%/$day/`
        fi

        echo "$line" >> $output_file

    done
}

replace_date()
{
    line=$1
    if [ "$line" != "${line/"%YMD-"/}" ]; then

        days=`echo "${line##*%YMD-}" | awk -F"%" '{print $1}'`
        day=`date +%Y%m%d -d ''-$days' day'`
        line=`echo $line | sed s/%YMD-$days%/$day/`
    fi

    echo "$line"
}


replace_symbolic_link()
{
    link_input_path=$1
    link_output_path=$2
    find "$link_input_path" -type l -exec file '{}' \;  | sed s/\'$// | awk -F": symbolic link to \`" '{ if( match("^/*$",$2) ==0 ){print $2;} }' >> "$link_output_path"
}

create_file_list()
{
    find_path=$1
    output_path=$2
   
    echo "create file list for '$find_path' into '$output_path'."

    find_path_tmp="$find_path.tmp"
    #
    find "$find_path" -type f > "$find_path_tmp"
   
    #
    replace_symbolic_link "$find_path" "$find_path_tmp"
   
    #
    cat "$find_path_tmp" | sort -n | uniq >> "$output_path"
   
    rm -f $find_path_tmp
}

full_backup()
{
    echo "full backup start."

    cat $backup_path | while read line
    do
        newLine=`replace_date $line`
        echo "replace date format. before:$line, end:$newLine."
        create_file_list "$newLine" "$fn_file_list"
    done
   
    find $conf_path -type f -name "*.cfg" >> $fn_file_list
   
    cat ""$fn_file_list"" | xargs -d "\n" md5sum >> "$fn_file_list_md5"

    copy_files

    echo "full backup finished."
}

echo "backup start."

inrc_type="inrc"
full_type="full"
backup_type=$1
strategy_type=$3
task_id=$2

tmp_path="/root/lcagent/case"
fn_file_list="${tmp_path}/file_list_${task_id}"
fn_file_list_md5="${fn_file_list}.md5"
backup_path="${tmp_path}/backup_path_${task_id}"

conf_path="/root/lcagent/autoBackup/file/${strategy_type}"
fileSysconf="$conf_path/fileSysconf.cfg"

if [ "$full_type" != "$backup_type" ];then
    inrc_backup
else
    full_backup
fi

echo "done."

相关推荐

Global site tag (gtag.js) - Google Analytics