已经拥有代码仓库/application/svndata/sadoc
备份思路,周日执行完整备份
周一至周六执行增量备份
[root@k8s01 application]# cat svnback.sh
#!/bin/bash
libai=$(date +%w)
projects=(sadoc)
for i in ${projects[@]}
do
SVN_DIR="/application/svndata/${i}"
BACK_DIR="/application/backup/${i}"
ID_PATH="/application/logs/id"
ID="${ID_PATH}/svn_id_${i}"
LOG_PATH="/application/logs/svnlog"
LOG="${LOG_PATH}/${i}_$(date -d today +"%Y-%m-%d".log)"
[ ! -d ${BACK_DIR} ] && mkdir -p ${BACK_DIR}
[ ! -d ${ID_PATH} ] && mkdir -p ${ID_PATH}
[ ! -d ${LOG_PATH} ] && mkdir -p ${LOG_PATH}
if [ ${libai} -eq 0 ];then
num_now=$(svnlook youngest ${SVN_DIR})
svnadmin dump ${SVN_DIR} -r 0:${num_now} > ${BACK_DIR}/${i}_full_backup_0_${num_now}_$(date -d today +"%Y%m%d")
if [ $? -eq 0 ];then
echo $num_now > ${ID}
echo "${i} full backup. now position is ${num_now}" >> ${LOG}
else
echo "${i} full backup. ${num_now} backup fail..." >> ${LOG}
fi
else
num_first=$(cat ${ID})
num_first=$( expr ${num_first} + 1 )
num_last=$(svnlook youngest ${SVN_DIR})
svnadmin dump ${SVN_DIR} -r ${num_first}:${num_last} --incremental > ${BACK_DIR}/${i}_increment_${num_first}_${num_last}_$(date -d today +"%Y%m%d")
if [ $? -eq 0 ];then
echo $num_last > ${ID}
echo "${i} increment backup. now position is from ${num_first} to ${num_last}" >> ${LOG}
else
echo "${i} increment backup. from ${num_first} to ${num_last} backup fail..." >> ${LOG}
fi
fi
find /application/backup/${i} -type f -mtime +30 |xargs rm -rfv
done
chmod a+x svnback.sh
##全量备份,把时间改成周日
##增量备份,把时间改成周一
还原操作
1、创建新的代码库
svnadmin create /application/svndata/test1
2、全量还原
svnadmin load /application/svndata/test1/ < /application/backup/sadoc/sadoc_full_backup_0_4_20220306
3、增量还原
svnadmin load /application/svndata/test1/ < /application/backup/sadoc/sadoc_increment_5_5_20220307
##虽然库还原了,但是配置文件并没有备份,这个脚本还需要完善