shell脚本快速发布及回滚php程序

your_website是网站根目录,publishlin与网站根目录同一级目录,用于存放需要发布的php程序(带目录全路径)

publish.sh脚本

#!/bin/sh
suffix=`date +%Y%m%d`
 
function listdir() {
    local current_dir base_dir targetfile targetdir
    base_dir=$1
    cd ${base_dir}
    current_dir=$(pwd)
    for dirlist in $(ls ${current_dir})
    do
        targetdir=`echo ${current_dir} | sed 's/publishlin/your_website/g'`
        if [ ! -d ${targetdir} ]; then
            mkdir ${targetdir}
        fi
        if [ -d ${dirlist} ]; then
            cd ${dirlist}
            listdir ${current_dir}/${dirlist}
            cd ..
        else
           targetfile=`echo ${current_dir}/${dirlist} | sed 's/publishlin/your_website/g'`
           if [ -f ${targetfile} ]; then
               mv ${targetfile} ${targetfile}${suffix}
           fi
           cp ${current_dir}/${dirlist} ${targetfile}
        fi
    done
}

if [ -z $1 ]; then
    echo "please input publish directory."
    echo "e.g. ./publish.sh /var/www/html/publishlin"
    exit 1
fi

if [ -d $1 ];
then
    listdir $1
elif [ -f $1 ];
then
    echo "please input a directory"
    exit 1
else
    echo "please input a exist directory"
    exit 1
fi

 

执行 ./publish.sh /var/www/html/publishlin 完成发布

 

rollback.sh脚本

#!/bin/sh
suffix=$2
 
function listdir() {
    local current_dir base_dir targetfile targetdir
    base_dir=$1
    cd ${base_dir}
    current_dir=$(pwd)
    for dirlist in $(ls ${current_dir})
    do
        if [ -d ${dirlist} ]; then
            cd ${dirlist}
            listdir ${current_dir}/${dirlist}
            cd ..
        else
           targetfile=`echo ${current_dir}/${dirlist} | sed 's/publishlin/your_website/g'`
           if [ -f ${targetfile}${suffix} ]; then
               rm -f ${targetfile}
               mv ${targetfile}${suffix} ${targetfile}
           else
              rm -f ${targetfile}
           fi
        fi
    done
}

if [ -z $1 -o -z $2 ]; then
echo "please input publish directory and rollback version."
echo "e.g. ./rollback.sh /var/www/html/publishlin 20140124"
exit 1
fi

if [ -d $1 ];
then
    listdir $1
elif [ -f $1 ];
then
    echo "please input a directory"
    exit 1
else
    echo "please input a exist directory"
    exit 1
fi

 

1. 上线前的备份工作: 按日期生成上线记录文件夹 文件结构目录和正式环境保持一致 备份你所涉及到的修改文件 2. 上线前的准备工作: 把你修改到的patch文件 到 PATCH_ROOT 目录中 文件结构目录和正式环境保持一致 3. 上线工作: diff -r -b 比较 备份环境 和 发布环境 文件差异; 再次确定修改是否正确 PATCH_ROOT 下的文件夹和文件 发布到正式环境 即可; 完成上线后,要检查系统功能是否正确。 4. 回滚工作: BAK_ROOT 下的文件夹和文件 回滚到正式环境 即可 ; 完成回滚后 要检查系统功能是否正确回滚。 5. shell脚本功能: === 参数配置 ===: #指定正式环境的路径 正式环境的文件 WEB_ROOT=/var/www/html echo ${WEB_ROOT} #指定发布环境的路径 发布环境的文件 PAT_ROOT=/home/chenlong/blog echo ${PAT_ROOT} #指定发布管理日志的路径 记录发布过程,完成文件备份和文件patch PUB_ROOT=/home/chenlong/Publish === 使用方法 ===: #./apply.sh blog /home/chenlong/patch_sh/list20100520.txt 例如 -bash-3.2$ ./apply.sh blog /home/chenlong/patch_sh/list20100520.txt /var/www/html /home/chenlong/blog /home/chenlong/Publish blog /home/chenlong/patch_sh/list20100520.txt /home/chenlong/patch_sh === cmd === :/home/chenlong/patch_sh/apply_cp.sh /var/www/html/wp-includes/js/common.js /home/chenlong/Publish/blog/2010-05-21/bak /bin/cp /var/www/html/wp-includes/js/common.js /home/chenlong/Publish/blog/2010-05-21/bak/var/www/html/wp-includes/js/common.js === cmd === :/home/chenlong/patch_sh/apply_cp.sh /var/www/html/upload_editor.php /home/chenlong/Publish/blog/2010-05-21/bak /bin/cp /var/www/html/upload_editor.php /home/chenlong/Publish/blog/2010-05-21/bak/var/www/html/upload_editor.php === cmd === :/home/chenlong/patch_sh/apply_cp.sh /var/www/html/BM/Tpl/default/Admin/Img/index.php /home/chenlong/Publish/blog/2010-05-21/bak /bin/cp /var/www/html/BM/Tpl/default/Admin/Img/index.php /home/chenlong/Publish/blog/2010-05-21/bak/var/www/html/BM/Tpl/default/Admin/Img/index.php === cmd === :/home/chenlong/patch_sh/apply_cp.sh /home/chenlong/blog/wp-includes/js/common.js /home/chenlong/Publish/blog/2010-05-21/patch /bin/cp /home/chenlong/blog/wp-includes/js/common.js /home/chenlong/Publish/blog/2010-05-21/patch/home/chenlong/blog/wp-includes/js/common.js === cmd === :/home/chenlong/patch_sh/apply_cp.sh /home/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值