最近项目的SVN仓库空间满了,于是准备迁移到新挂载的目录,顺便清理下版本号,虽然是个小问题,不过遇上了还是记一下吧。
直接上代码,请不要无脑运行,先修改下相关的路径和参数后再运行
#!/bin/bash
##执行完毕后,版本号会重新计算,可以先尝试cleanup,如果不行请重新checkout一下,然后替换掉原来的.svn文件夹即可
##dumpFile : /usr/svndump/xxx.dmg
export PATH="$PATH"
#svnadmin命令路径
SVNADMIN="/path/svnadmin"
#svn备份目录
SVNHOTCOPY="/path/svncopy/"
if [ ! -d "${SVNHOTCOPY}" ]
then
`mkdir -p "${SVNHOTCOPY}"`
fi
if [ ! -d "/usr/svndump" ]
then
`mkdir -p "/usr/svndump"`
fi
dump(){
for item in `/bin/ls $1`
do
if [ "${item}" = "conf" ]
then
continue;
fi
SVNREPO="$1/${item}"
LOGVERSION=`svnlook youngest ${SVNREPO}`
echo "path=>${SVNREPO},logversion=>${LOGVERSION}"
$SVNADMIN hotcopy --clean-logs ${SVNREPO} "${SVNHOTCOPY}${item}"
#svndump文件,路径自行设定
SVNDUMP="/usr/svndump/${item}.dmg"
#获取最新的10个版本号
if [ $LOGVERSION -gt 10 ]
then
STARTVERSION=`expr $LOGVERSION - 10 `
$SVNADMIN dump $SVNREPO -r $STARTVERSION:$LOGVERSION > "${SVNDUMP}"
else
$SVNADMIN dump $SVNREPO > "${SVNDUMP}"
fi
done
echo "[DUMP OK]"
}
load(){
for sub in `ls /usr/svndump | xargs -i expr match {} "\(.*\)\.dmg"`
do
if [ ! -d "/usr/svn/${sub}" ]
then
${SVNADMIN} create --config-dir "/path/svn/conf" "/newRepoPath/${sub}"
fi
#dmg文件务必与dumpFile路径保持一致
${SVNADMIN} load "/newRepoPath/${sub}" < "/usr/svndump/${sub}.dmg"
#设置预提交svn hooks,hook文件请先设置执行权限,视需求自行配置
##\cp -f "/path/pre-commit" "/newRepoPath/${sub}/hooks/"
done
echo "[LOAD OK]"
}
case "$1" in
'dump')
if [ $# -lt 2 ]
then
echo "please use command: /svndump.sh dump [repopath]"
else
dump $2
fi
;;
'load')
load
;;
*)
echo "command: /svndump.sh dump [repopath] or /svndump.sh load"
;;
esac
对于项目比较大,svn版本号过多的情况还是比较适用的,上面shell中默认取最新的10个版本号,如有其他要求,请查看注释自行修改范围即可