svn 日志备份脚本 。未测试。大致是对的。如果有需要,按要求修改
此处没有添加到crontab中。自己添加
1目标:
每月进行一次全量备份,其它进行增量备份
路径到/home/backup/svn/
全量备份文件名为:weekly_fully_backup.yymmdd,增量备份文件命名为:daily-incremental-backup.yymmdd
时间:每晚21点开始
2 ~/weekly_backup.sh 脚本 全量备份
#定义SVN库
$svn_repos="/home/svn/repos/project1";
#定义备份目录
$backup_dir="/home/backup/svn/";
#定义备份名称
$next_backup_file = "mouth_fully_backup.".`date +%Y%m`;
#显示备份的最后版本号:
$youngest=`svnlook youngest $svn_repos`;
echo ""Backing up to revision $youngestn";"
#备份到最新版本
$svnadmin_cmd="svnadmin dump -r 0:$youngest $svn_repos >$backup_dir/$next_backup_file";
`$svnadmin_cmd`;
#记录备份的版本号
echo "$youngest" > $backup_dir/last_backup;
echo "Backing up to revision $youngest by mouth_backup.sh. \n" > $backup_dir/log_backup;
#是否压缩:
gzip -9 $backup_dir/$next_backup_file
3建立增量备份脚本:
daily_backup.sh 增量备份
#定义SVN库
$svn_repos="/home/svn/repos/project1";
#定义备份目录
$backup_dir="/home/backup/svn/";
#定义备份名称
$next_backup_file = "daily_incremental_backup.".`date +%Y%m%d`;
#获取最后备份的版本
$previous_youngest=`cat $backup_dir/last_backup`
#得到最新的版本号
$youngest=`svnlook youngest $svn_repos`;
#查看是否需要备份
if [ $youngest eq $previous_youngest ]
then
echo "no new revision to backup. /n"
exit 0
fi
#获取最新的版本
$first_rev=`let “$previous_youngest"++`
#备份到最新版本
svnadmin dump --incremental -r $previous_youngest:$youngest $svn_repos > $backup_dir/$next_backup_file;
#写入日志
echo "$youngest" > $backup_dir/last_backup;
echo "Backing up to revision by daily_backup.sh :$youngest : `date +%Y%m%d` \n" >> $backup_dir/log_backup;
#压缩
gzip -g $backup_dir/$next_backup_file
4恢复
1创建库
$backup_dir="/home/backup/svn/";
$previous_youngest=`cat $backup_dir/last_backup`
$last_day=""
mkdir /home/svn/svn1
svnadmin create /home/svn/svn1
svnadmin load /home/svn/svn1 < mouth_fully_backup.`date +%Y%m`
for i in $backup_dir/daily_incremental_backup.`date +%Y%m`*
do
svnadmin load /home/svn/svn1 < $i
last_day=$i
done
$youngest=`svnlook youngest $svn_repos`;
if [ $youngest eq $previous_youngest ]
then
echo " Verision has been backuped to `$last_day | awk -F"." '{print $2}' `. /n"
echo "The last version is $youngest./n"
fi
exit 0
此处没有添加到crontab中。自己添加
1目标:
每月进行一次全量备份,其它进行增量备份
路径到/home/backup/svn/
全量备份文件名为:weekly_fully_backup.yymmdd,增量备份文件命名为:daily-incremental-backup.yymmdd
时间:每晚21点开始
2 ~/weekly_backup.sh 脚本 全量备份
#定义SVN库
$svn_repos="/home/svn/repos/project1";
#定义备份目录
$backup_dir="/home/backup/svn/";
#定义备份名称
$next_backup_file = "mouth_fully_backup.".`date +%Y%m`;
#显示备份的最后版本号:
$youngest=`svnlook youngest $svn_repos`;
echo ""Backing up to revision $youngestn";"
#备份到最新版本
$svnadmin_cmd="svnadmin dump -r 0:$youngest $svn_repos >$backup_dir/$next_backup_file";
`$svnadmin_cmd`;
#记录备份的版本号
echo "$youngest" > $backup_dir/last_backup;
echo "Backing up to revision $youngest by mouth_backup.sh. \n" > $backup_dir/log_backup;
#是否压缩:
gzip -9 $backup_dir/$next_backup_file
3建立增量备份脚本:
daily_backup.sh 增量备份
#定义SVN库
$svn_repos="/home/svn/repos/project1";
#定义备份目录
$backup_dir="/home/backup/svn/";
#定义备份名称
$next_backup_file = "daily_incremental_backup.".`date +%Y%m%d`;
#获取最后备份的版本
$previous_youngest=`cat $backup_dir/last_backup`
#得到最新的版本号
$youngest=`svnlook youngest $svn_repos`;
#查看是否需要备份
if [ $youngest eq $previous_youngest ]
then
echo "no new revision to backup. /n"
exit 0
fi
#获取最新的版本
$first_rev=`let “$previous_youngest"++`
#备份到最新版本
svnadmin dump --incremental -r $previous_youngest:$youngest $svn_repos > $backup_dir/$next_backup_file;
#写入日志
echo "$youngest" > $backup_dir/last_backup;
echo "Backing up to revision by daily_backup.sh :$youngest : `date +%Y%m%d` \n" >> $backup_dir/log_backup;
#压缩
gzip -g $backup_dir/$next_backup_file
4恢复
1创建库
$backup_dir="/home/backup/svn/";
$previous_youngest=`cat $backup_dir/last_backup`
$last_day=""
mkdir /home/svn/svn1
svnadmin create /home/svn/svn1
svnadmin load /home/svn/svn1 < mouth_fully_backup.`date +%Y%m`
for i in $backup_dir/daily_incremental_backup.`date +%Y%m`*
do
svnadmin load /home/svn/svn1 < $i
last_day=$i
done
$youngest=`svnlook youngest $svn_repos`;
if [ $youngest eq $previous_youngest ]
then
echo " Verision has been backuped to `$last_day | awk -F"." '{print $2}' `. /n"
echo "The last version is $youngest./n"
fi
exit 0
编辑回复