使用环境: linux, 需配置 php运行命令, 打开PHP 禁用的 exec 函数.
svn库导出打包:?
在svn库根目录下新建个 svndump.php文件, 文件内容如下, 然后目录下执行 php svndump.php, 等待打包完成.
<?php
function doCmd($cmd){
echo $cmd . "\n";
exec($cmd);
echo "\n";
}
$filenames = scandir(dirname(__FILE__));
$folders = [];
foreach ($filenames as $k => $v) {
if (is_dir($v) && strpos($v, '.') === false) {
//导出库
doCmd('svnadmin dump ' . $v . ' > ' . $v . '.dump');
//导出uuid
doCmd('cp ' . $v . '/db/uuid '. $v .'.uuid');
}
}
//压缩文件
doCmd('tar -zcvf svndump.tar.gz *.dump *.uuid');
//删除文件
doCmd('rm -rf *.dump *.uuid');
svn库导入:
把上面SVN库导出的压缩包文件svndump.tar.gz,? 复制到新的 SVN库根目录;
在SVN库根目录新建个svnload.php, 文件内容如下, 然后在目录下执行 php svnload.php , 等待解压部署导入SVN库完成.
<?php
function doCmd($cmd) {
echo $cmd . "\n";
exec($cmd);
echo "\n";
}
//解压文件包
doCmd('tar -zxvf svndump.tar.gz');
$filenames = scandir(dirname(__FILE__));
$folders = [];
foreach ($filenames as $k => $v) {
if (strpos($v, '.dump') !== false) {
$v = str_replace('.dump', '', $v);
//新建svn库
doCmd('svnadmin create ' . $v);
//导入svn库
doCmd('svnadmin load ' . $v . ' < ' . $v . '.dump');
//导入uuid
doCmd('rm -rf ' . $v . '/db/uuid');
doCmd('cp ' . $v . '.uuid ' . $v . '/db/uuid');
//覆盖svnserve.conf
doCmd('rm -rf ' . $v . '/conf/svnserve.conf');
doCmd('cp svnserve.conf ' . $v . '/conf/');
}
}
//删除文件
doCmd('rm -rf *.dump *.uuid');
注: 仅适合于版本量少的库进行备份迁移!
|