#!/usr/bin/perl -w
my $svn_repos="/home/svn/repos/project1";
my $backup_dir="/home/backup/svn/";
my $next_backup_file = "weekly_fully_backup.".`date +%Y%m%d`;
#!/usr/bin/perl -w
my $svn_repos="/home/svn/repos/project1";
my $backup_dir="/home/backup/svn/";
my $next_backup_file = "daily_incremental_backup.".`date +%Y%m%d`;
open(IN,"$backup_dir/last_backed_up");
$previous_youngest = <IN>;
chomp $previous_youngest;
close IN;
$youngest=`svnlook youngest $svn_repos`;
chomp $youngest;
if ($youngest eq $previous_youngest)
{
print "No new revisions to backup.n";
exit 0;
}
my $first_rev = $previous_youngest + 1;
print "Backing up revisions $youngest ...n";
my $svnadmin_cmd = "svnadmin dump --incremental --revision $first_revyoungest $svn_repos > $backup_dir/$next_backup_file";
`$svnadmin_cmd`;
open(LOG,">$backup_dir/last_backed_up"); #记录备份的版本号
print LOG $youngest;
close LOG;
#如果想节约空间,则再执行下面的压缩脚本
print "Compressing dump file...n";
print `gzip -g $backup_dir/$next_backup_file`;
#! /usr/bin/perl
## Author:xuejiang
## 2007-11-10
## http://www.scmbbs.com
use strict;
use Carp;
use Net::SMTP;
#### defined the var #######
my $smtp =Net::SMTP->new('mail.scmbbs.com', Timeout => 30, Debug => 0)|| die "cann't connect to mail.scmbbs.comn";
my $bkrepos="/home/backup/svn/".&get_day;#定义备份路径
my $ssrepos="http://www.scmbbs.com/repos";#定义仓库url
my @repos = ("project1","project2");
my $title="echo "如下是昨晚备份结果与真实库对比的情况,如果给出备份版本数,则表示备份成功;如果给报错信息或没有备份版本数,则表示备份失败:" >./report";
system $title || die "exec failedn";
foreach my $myrepos(@repos)
{
my $bkrepos1=$bkrepos."/".$myrepos;
my $ssrepos1=$ssrepos."/".$myrepos;
my $svnlookbk1 = "echo "$myrepos 昨晚备份的版本是:">>./report;svnlook youngest ".$bkrepos1." >> ./report 2>&1";
my $svnlookss1 = "echo "$myrepos 真实库中的最新版本及最后修改时间是:">>./report;svn log -r'HEAD' ".$ssrepos1." >> ./report 2>&1";
system $svnlookbk1 || die "exec failedn";
system $svnlookss1 || die "exec failedn";
}
my $body ="echo "=========================================================================" >>./report";
my $bottom ="echo "备份位置:来自http://www.scmbbs.com的".$bkrepos."" >>./report";
system $body || die "exec failedn";
system $bottom || die "exec failedn";
###### report the result ####
open(SESAME,"./report")|| die "can not open ./report";
my @svnnews = <SESAME>;
close(SESAME);
foreach my $line1 (@svnnews)
{
print $line1."n";
}
my @email_addresses =("scm@list.scmbbs.com","leader1@scmbbs.com","leader2@scmbbs.com");
my $to = join(', ', @email_addresses);
$smtp->mail("scm@scmbbs.com");
$smtp->recipient(@email_addresses);
$smtp->data();
$smtp->datasend("Toton");
$smtp->datasend("From: svnReport@scmbbs.comn");
$smtp->datasend("Subject:svn备份检查报告".&get_today."n");
$smtp->datasend("Reply-to:scm@scmbbs.comn");
$smtp->datasend("@svnnews");
$smtp->dataend();
$smtp->quit;