此前写过Subversion仓库Dump自动化备份脚本,该脚本实现从数据库读取备份记录并生成静态页面进行展示。将脚本加入系统定时任务,即可实现在指定的周期刷新数据。

|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
#!/bin/bash # 最后更新:2025/07/21 # 脚本开发:刘智林 # 脚本功能:配置管理svn备份前端页面生成器 # 本地工作空间 baseDir="${PWD}" dataDir="${baseDir}/datacenter" dataDep="${baseDir}/data_deploy" dataMon="${baseDir}/data_monitor" # 网页存储目录 htmlDir="/var/www/html" repoWeb="${htmlDir}/repbackup" repoInf="${repoWeb}/inf" repoWeb="${htmlDir}/repbackup" # 数据库信息 dbsUser="svnbackup" dbsPass="svnbackup@2025" dbsHost="10.10.100.101" # 数据表信息 repoTab="repository" backTab="repository_bak" # 数据表文件 repList="${dataDir}/repbackup.txt" # 配置基本环境 [ ! -d ${dataDir} ] && mkdir -p ${dataDir} [ ! -d ${repoInf} ] && mkdir -p ${repoInf} # 更新基础数据 sqlCont="select repName from ${dbsUser}.${repoTab} WHERE repType = 'svn' AND disFlag = '1'" mysql -u ${dbsUser} -p${dbsPass} --batch --skip-column-names -e "${sqlCont}" > ${repList} # 生成备份记录(每个仓库备份记录) echo "生成备份数据(每个仓库备份记录)..." for bakName in `cat ${repList}` do sqlCont="select * from ${dbsUser}.${repoRec} WHERE repName = '${bakName}' order by ID DESC;" mysql -u ${dbsUser} -p${dbsPass} --batch --skip-column-names -e "${sqlCont}" > ${tmpList} htmFile="${repoInf}/${bakName}_list.html" [ -e ${htmFile} ] && > ${htmFile} numFlag=0 cat ${tmpList} | while read ID repName bakType lastVer bgnDate bgnTime endDate endTime bakFile rptData rptMark do numFlag=`expr ${numFlag} + 1` [ "${bakType}" = "0" ] && bakType="全量" || bakType="增量" [ "${rptData}" = "0" ] && rptData="正常" || rptData="异常" echo "<li><div class='wmode0'>${numFlag}</div><div class='wmode5'>${repName}</div><div class='wmode1'>${bakType}</div><div class='wmode4'>${lastVer}</div><div class='wmode7'>${bgnDate} ${bgnTime}</div><div class='wmode3'>${endTime}</div><div class='wmode1'>${bakFile}</div><div class='wmode2'>${rptData}</div><div class='wmode8'>${rptMark}</div>" >> ${htmFile} done done # 生成备份记录(全部仓库备份记录) echo "生成备份记录(全部仓库备份记录)..." sqlCont="select * from ${dbsUser}.${repoRec} order by ID DESC LIMIT 999;" mysql -u ${dbsUser} -p${dbsPass} --batch --skip-column-names -e "${sqlCont}" > ${tmpList} htmFile="${repoInf}/rep_index_list.html" [ -e ${htmFile} ] && > ${htmFile} numFlag=0 cat ${tmpList} | while read ID repName bakType lastVer bgnDate bgnTime endDate endTime bakFile rptData rptMark do numFlag=`expr ${numFlag} + 1` [ "${bakType}" = "0" ] && bakType="全量" || bakType="增量" [ "${rptData}" = "0" ] && rptData="正常" || rptData="异常" echo "<li><div class='wmode0'>${numFlag}</div><div class='wmode5'><a href='rep_${repName}.html'>${repName}</a></div><div class='wmode1'>${bakType}</div><div class='wmode4'>${lastVer}</div><div class='wmode7'>${bgnDate} ${bgnTime}</div><div class='wmode3'>${endTime}</div><div class='wmode1'>${bakFile}</div><div class='wmode2'>${rptData}</div><div class='wmode8'>${rptMark}</div>" >> ${htmFile} done # 生成信息页面(每个仓库备份首页) echo "生成信息页面(每个仓库备份首页)..." for bakName in `cat ${repList}` do htmFile="${repoWeb}/rep_${bakName}.html" [ ! -e ${htmFile} ] && cp ${htmFile%/*}/theme/rep_template.html ${htmFile} && sed -i "s/rep_list/${bakName}_list/g;s/仓库备份记录/${bakName}备份记录/g" ${htmFile} done |
在网站存储目录中创建以下文件后再执行脚本,否则无法正常运行。
主题文件theme/rep_index.html
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
<html lang="zh_CN"> <head> <!--#include file="theme/header.html"--> <base target="_blank"> <title>仓库备份记录-配置管理工具</title> </head> <body> <div class="wrap"> <div class="wFull"> <div class="infTitle"> <!--#include file="theme/repTitle.html"--> </div> <div class="infContent"> <!--#include file="rep/rep_index_list.html"--> </div> </div> </div> <!--#include file="theme/footer.html"--> </body> </html> |
主题文件theme/footer.html
|
1 2 3 |
<div class="wrap"> <div class="footer"><a href="http://10.10.100.100/repbackup/rep_index.html">仓库备份记录</a></div> </div> |
主题文件theme/header.html
|
1 2 |
<meta charset="UTF-8"> <link rel="stylesheet" href="theme/style.css" type="text/css" media="all"> |
主题文件theme/rep_template.html
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
<html lang="zh_CN"> <header> <!--#include file="theme/header.html"--> <base target="_blank"> <title>仓库备份记录-配置管理工具</title> </header> <body> <div class="wrap"> <div class="wFull"> <div class="infTitle"> <!--#include file="theme/repTitle.html"--> </div> <div class="infContent"> <!--#include file="rep/rep_list.html"--> </div> </div> </div> <!--#include file="theme/footer.html"--> </body> </html> |
主题文件theme/repTitle.html
|
1 |
<div class='wmode0'>序号</div><div class='wmode5'>仓库名称</div><div class='wmode1'>模式</div><div class='wmode4'>最新版本</div><div class='wmode7'>开始时间</div><div class='wmode3'>结束时间</div><div class='wmode1'>文件大小</div><div class='wmode2'>结果</div><div class='wmode8'>说明</div> |
主题风格theme/style.css
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
body {margin:0; padding:0; line-height:20px; font-size:12px;} a {text-decoration:none;} hr {color:#DDDDDD;} .wrap {clear:both; text-align:left; width:100%;} .wrap .wFull {width:100%; margin-bottom:32px; overflow:hidden;} .wrap .index_list {text-align:center; vertical:center;} .wrap .index_list li {list-style:none;} .wrap .infTitle {clear:both; position:fixed; top:0; left:12px; border-bottom:1px solid #FFFFFF; z-index:999; height:20px; width:98%; font-size:14px; font-weight:bold; text-align:center; text-overflow:ellipsis; white-space:nowrap; overflow:hidden;} .wrap .infContent {width:98%; margin:20px 0 0 12px;} .wrap .infContent li {list-style:none; text-align:center; overflow:hidden; text-overflow:ellipsis; white-space:nowrap;} .wmode0, .wmode1, .wmode2, .wmode3, .wmode4, .wmode5, .wmode6, .wmode7, .wmode8, .wmode9, .wmodex {float:left; padding:0 6px; text-overflow:ellipsis; white-space:nowrap; overflow:hidden; border-top:1px solid #FFF;} .wmode0 {width:3%; background-color:#CDCDCD;} .wmode1 {width:5%; background-color:#FFBBBB;} .wmode2 {width:5%; background-color:#FFBBFF;} .wmode3 {width:6%; background-color:#CCAAAA;} .wmode4 {width:6%; background-color:#CCAACC;} .wmode5 {width:10%; background-color:#FFBBDD;} .wmode6 {width:10%; background-color:#BBBBDD;} .wmode7 {width:12%; background-color:#DDBBDD;} .wmode8 {width:16%; background-color:#AABBDD;} .wmode9 {width:20%; background-color:#CCDDBB;} .wmodex {width:25%; background-color:#BBDDBB;} .getInfo {float:left; width:100%; line-height:24px; margin-bottom:1px; background-color:#EEEEEE;} .getInfo div {float:left; margin:0;} .getInfo span {float:left; padding:0 20px; margin-right:6px; background-color:#DDEEDD; font-weight:bold;} .getInfo a {margin-right:4px;} .footer {clear:both; width:98%; background-color:#FFFFFF; padding:3px 0; position:fixed; bottom:0; left:12px;} .footer a {margin-right:12px; color:#118811;} |
原创文章禁止转载:技术学堂 » Subversion仓库Dump自动化备份前端生成脚本

技术学堂















