linux 下 文件更新&回滚脚本

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

#!/bin/sh
#by airzen 20130131 

filename=$1
newfilename=$filename.new
bakfilename=$filename.bak

if [ ! -f $filename ]; then
    printf "$filename NOT is exist\n"
    exit
fi

function upgrade()
{
    if [ -f $newfilename ]; then
        mv $filename $bakfilename
        mv $newfilename $filename
    else
        printf "$newfilename NOT is exist\n"
    fi
}

function restore()
{
    if [ -f $bakfilename ]; then
        mv $filename $newfilename
        mv $bakfilename $filename
    else
       printf "$bakfilename NOT is exist\n"
    fi 
}

if [ "$2" = "go" ]; then
    upgrade
elif [ "$2" = "back" ]; then
    restore
else
    printf "Usage:CMD {path/fn.ext}  {go|back} \n"
    printf "go   - MUST exist the [path/fn.ext.new] \n"
    printf "back - MUST exist the [path/fn.ext.bak] \n"
fi