Share a recently written shell script that enables you to back up the production line files and rollback operations by the file directory structure of the published package.
1#!/bin/SH2Path="/home/www/site1"3pub= $path"/release/pub/mboxii/trunk"#发布目录4bak= $path"/release/bak"#生产目录备份文件5Prod=$path #生产目录6pub_file_plus= $path"/release/pub_plus.txt"#增量文件: Publish a new file list log for a package relative to the production package7 8 #执行备份9 Dobak () {Ten #删除之前的备份文件 (clip) One      for file inch$(ls$bak) A      Do -#Echo$bak"/"$file -         RM-RF $bak"/"$file the      Done -     if[ -F $pub _file_plus] -      Then -         RM-RF $pub _file_plus +     fi - #将发布目录对应的生产目录的文件 (clip) backup by original structure +     functionRead_dir () { A          for file inch`ls$1` at          Do -dir_r=$1"/"$file -dir_p=${dir_r/# $pub/$prod} -dir_b=${dir_r/# $pub/$bak} -             if[ -d $dir _r] #注意此处之间一定要加上空格, or it will be an error -              Then in                 if[ -d $dir _p] -                  Then to#Echo$dir _b +                     mkdir-p-m755$dir _b #创建对应的备份文件夹 -Read_dir $1"/"$file#递归子目录 the                 Else *                     Echo$dir _p &>>$pub _file_plus $                 fiPanax Notoginseng             Else -                 if[ -F $dir _p] the                  Then +#Echo$dir _p" "$dir _b A                     CP$dir _p $dir _b the                 Else +                     Echo$dir _p &>>$pub _file_plus -                 fi $             fi $          Done -     } - Read_dir $pub the     Echo 'Backup Complete' - }Wuyi  the #执行发布 - dopub () { Wu     CP-arf $pub/*$prod - Echo ' release complete ' About } $  - #执行回滚 - Dorollback () { - For file in $ (cat $pub _file_plus) A  Do + #echo $bak "/" $file the RM-RF $file -  Done $ cp-arf $bak/* $prod the echo ' rollback complete ' the } the  the usage () { - Cat <<eof in How to use the product release script: the 1 Backup the 2 Release About 3 Rolling back the 4 Exit the EOF the } +  - usage the echo ' Please enter the operation command: 'Bayi Read cmd the While [$cmd! = ' exit '] the  Do - Case $cmd in - 1) the Dobak the             ;;  the 2) the dopub -             ;; the 3) the Dorollback the             ;;94 4) the #exit the  Break the             ;;98         *) About usage -             ;;101 Esac102 echo ' Please enter the operation command: '103 Read cmd104  Done
Shell Scripting for backup, publish, rollback by directory