subversion锁定解除、升级、备份与恢复
时间:2010-11-16 来源:sun9527
1.发生琐定,解除步骤:
A.确定没有存取.关闭httpd服务器.
B.成为管理员身份
C.执行svnadmin recover /path/to/repo命令
D.重启动subversion.
//注意:
A.以管理员身份,非root身份,如果一root身份,要重新chmod,库的权限.
2.升级的步骤:
A.现有版本svnadmin ,将档案库dump出来
B.升级到新版的subversion
C.删除就档案库,再原处以新版本subversion,建立新的空档案库.
D.再利用新版本svnadmin ,将档案库load到刚刚建立好的档案库.
实例:
//导出
$svnlook youngest oldrepo
$svnadmin dump oldrepo >; dumpfile
//还原
$svnadmin load newrepo < dumpfile
3.即时备份目录
$svnadmin hotcopy /path/to/repo /backup/repo
4.渐进式备份实现.
A.建立文件hot-backup.perl.内容如下:
#!/usr/bin/perl -w
use strict;
my $repos_path = '/path/to/repos';
my $dumpfile = '/usr/backup/svn-dumpfile';
my $last_dumped = '/var/log/svn-last-dumped';
my $svnlook = '/usr/local/subversion/bin/svnlook';
my $svnadmin = '/usr/local/subversion/bin/svnadmin';
# Figure out the starting revision. Use 0 if we cannot read the
# last-dumped file, else use the revision in that file incremented
# by 1.
my $new_start = 0;
if (open LASTDUMPED, $last_dumped)
{
my $line = <LASTDUMPED>;;
if (defined $line and $line =~ /^(\d+)/)
{
$new_start = $1 + 1;
}
close LASTDUMPED;
}
# Query the youngest revision in the repos.
my $youngest = `$svnlook youngest $repos_path`;
defined $youngest && $youngest =~ /^\d+$/
or die "$0: 'svnlook youngest $repos_path' cannot get youngest revision.\n";
chomp $youngest;
# Do the backup.
system("$svnadmin dump $repos_path --revision $new_startyoungest --incremental >;>; $dumpfile.tmp" == 0
or die "$0: svnadmin dump to '$dumpfile.tmp' failed.\n";
# Store a new last-dumped revision.
open LASTDUMPED, ">; $last_dumped.tmp"
or die "$0: cannot open '$last_dumped.tmp' for writing: $!\n";
print LASTDUMPED "$youngest\n";
close LASTDUMPED
or die "$0: error in closing '$last_dumped.tmp' for writing: $!\n";
# Rename to final locations.
rename("$dumpfile.tmp", $dumpfile)
or die "$0: cannot rename '$dumpfile.tmp' to '$dumpfile': $!\n";
rename("$last_dumped.tmp", $last_dumped)
or die "$0: cannot rename '$last_dumped.tmp' to '$last_dumped': $!\n";
# All done!
B.备份.先编辑hot-backup.perl里面正确的路径名.
#vi hot-backup.perl修改为自己的路径:
my $repos_path = '/path/to/repos';
my $dumpfile = '/usr/backup/svn-dumpfile';
my $last_dumped = '/var/log/svn-last-dumped';
my $svnlook = '/usr/local/subversion/bin/svnlook';
my $svnadmin = '/usr/local/subversion/bin/svnadmin';
#perl hot-backup.perl得到的文件是/usr/backup/svn-dumpfile
c.还原
1.建立新的仓库
#svnadmin create /usr/local/repo/newrepo
2.还原信息
#svnadmin load /usr/local/repo/newrepo < /usr/backup/svn-dumpfile
3.注意:以后每天都备份.再执行还原即可,不必新建仓库了.
4.为了每段时间能验证备份的有效性.最好是建立一个验证仓库,用来还原,看信息是否正常。
d.有提交,就备份.进入仓库
#mv /hooks/post-commit.tmpl /hooks/post-commit
#vi /hooks/post-commit
添加内容在后面
perl /usr/local/subversion/backup/hot-backup.perl
每次提交触发一次备份
E.修改一下上面的程序,让能接受参数输入
#!/usr/bin/perl -w
use strict;
my $repos_path = $ARGV[0];
my $dumpfile = $ARGV[1];
my $last_dumped = $ARGV[2];
my $svnlook = '/usr/local/subversion/bin/svnlook';
my $svnadmin = '/usr/local/subversion/bin/svnadmin';
#for usage
if(@ARGV != 3 )
{
print "$0:[/path/to/repo] [/backup/dumpfile] [/var/log/lastdump]\n";
exit 1 ;
}
# Figure out the starting revision. Use 0 if we cannot read the
# last-dumped file, else use the revision in that file incremented
# by 1.
my $new_start = 0;
if (open LASTDUMPED, $last_dumped)
{
my $line = <LASTDUMPED>;;
if (defined $line and $line =~ /^(\d+)/)
{
$new_start = $1 + 1;
}
close LASTDUMPED;
}
# Query the youngest revision in the repos.
my $youngest = `$svnlook youngest $repos_path`;
defined $youngest && $youngest =~ /^\d+$/
or die "$0: 'svnlook youngest $repos_path' cannot get youngest revision.\n";
chomp $youngest;
# Do the backup.
system("$svnadmin dump $repos_path --revision $new_startyoungest --incremental >;>; $dumpfile.tmp" == 0
or die "$0: svnadmin dump to '$dumpfile.tmp' failed.\n";
# Store a new last-dumped revision.
open LASTDUMPED, ">; $last_dumped.tmp"
or die "$0: cannot open '$last_dumped.tmp' for writing: $!\n";
print LASTDUMPED "$youngest\n";
close LASTDUMPED
or die "$0: error in closing '$last_dumped.tmp' for writing: $!\n";
# Rename to final locations.
rename("$dumpfile.tmp", $dumpfile)
or die "$0: cannot rename '$dumpfile.tmp' to '$dumpfile': $!\n";
rename("$last_dumped.tmp", $last_dumped)
or die "$0: cannot rename '$last_dumped.tmp' to '$last_dumped': $!\n";
# All done!
F.有提交,就备份.进入仓库
#mv /hooks/post-commit.tmpl /hooks/post-commit
#vi /hooks/post-commit
添加内容在后面
perl /usr/local/subversion/backup/hot-backup.pl /usr/local/repo/webaddress /usr/local/subversion/backup/webaddress /var/log/webaddress
每次提交触发一次备份
5.hot-backup.py完整备份
6.tar包完整备份
1.进入仓库的根目录/usrl/local/
#cd /usr/local/
2.备份整个目录.
#tar -cf repo.tar /usr/local/repo.
3.还原时候来到根目录/usrl/local/
#tar -xvf repo.tar
4.也可以备份单个目录.
#tar -cf svn.tar /usr/local/repo/svn.
5.还原单个目录到目录/usr/local/repo/
#tar -xvf svn.tar
6.每天的自动备份脚本backup.sh.放于/usrl/local/subversion/backup目录下
#!/bin/sh
USAGE="Usage:`basename $0` [-f|-d] [files|directories]"
if [ $# -lt 2 ] ; then
echo "$USAGE";
exit 1 ;
fi
case "$1" in
-f) shift
TARGES="-tvf" ;
for i in "$@" ;
do
if [ -f "$i" ] ; then
FILES = `tar $TAGES "$i" 2 >; /dev/null`
if [ $? -eq 0 ] ; then
echo ; echo "$i" ; echo "$FILES"
else
echo "ERRORi not a tar file."
fi
else
echo "ERRORi not a file.";
fi
done
;;
-d) shift
TARGES="-cvf" ;
if [ -f backup.tar ] ; then
mv backup.tar backup1.tar
fi
tar $TARGES backup.tar "$@"
;;
*) echo "$USAGE"
exit 0
;;
esac
exit $?
8.固定时间运行脚本
A.建立运行脚本backup:
20 18 * * * /usr/local/subversion/backup/backup.sh -d /usr/local/repo
B.启用脚本
#crontab backup
#crontab -l 查看运行的脚本
20 18 * * * /usr/local/subversion/backup/backup.sh -d /usr/local/repo //每日18:20,下班后20分钟
注意:
1.linux直接cp的备份仓库能在nt下使用,但是nt的复制不能在linux下使用.