#!/usr/bin/perl -w use strict; my $repos_path = $ARGV[0]; my $dumpfile = $ARGV[1]; my $type = $ARGV[2]; my $bin_svnadmin = `which svnadmin`; my $bin_svnlook = `which svnlook`; my $bin_bz2 = `which bzip2`; $bin_svnlook =~ s/\n//; $bin_svnadmin =~ s/\n//; $bin_bz2 =~ s/\n//; if ($bin_svnadmin eq "") {$bin_svnadmin = "/usr/bin/svnadmin"}; if ($bin_svnlook eq "") {$bin_svnlook = "/usr/bin/svnlook"}; if ($bin_bz2 eq "") {$bin_bz2 = "/bin/bzip2"}; # 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, "$dumpfile.last") { my $line = ; if (defined $line and $line =~ /^(\d+)/) { $new_start = $1 + 1; } close LASTDUMPED; } # Query the youngest revision in the repos. my $youngest = `$bin_svnlook youngest $repos_path`; defined $youngest && $youngest =~ /^\d+$/ or die "$0: 'svnlook youngest $repos_path' cannot get youngest revision.\n"; chomp $youngest; if ($type eq "incremental") { if ($new_start > $youngest) { print "Nothing to do!\n"; } else { ## Do the backup. system("$bin_svnadmin dump $repos_path --revision $new_start:$youngest --incremental >> $dumpfile.tmp") == 0 or die "$0: svnadmin dump to '$dumpfile.tmp' failed.\n"; # Store a new last-dumped revision. open LASTDUMPED, "> $dumpfile.last.tmp" or die "$0: cannot open '$dumpfile.last.tmp' for writing: $!\n"; print LASTDUMPED "$youngest\n"; close LASTDUMPED or die "$0: error in closing '$dumpfile.last.tmp' for writing: $!\n"; # Rename to final locations. rename("$dumpfile.tmp", "$dumpfile.$new_start.$youngest") or die "$0: cannot rename '$dumpfile.tmp' to '$dumpfile': $!\n"; rename("$dumpfile.last.tmp", "$dumpfile.last") or die "$0: cannot rename '$dumpfile.last.tmp' to '$dumpfile.last': $!\n"; system("$bin_bz2 $dumpfile.$new_start.$youngest") == 0 or die "$0: compressing dump file $dumpfile.$new_start.$youngest failed.\n"; } } else { system("$bin_svnadmin dump $repos_path >> $dumpfile.full.tmp") == 0 or die "$0: svnadmin dump to '$dumpfile.tmp' failed.\n"; rename("$dumpfile.full.tmp", "$dumpfile.full") or die "$0: cannot rename '$dumpfile.full.tmp' to '$dumpfile.full': $!\n"; system("$bin_bz2 -f $dumpfile.full") == 0 or die "$0: compressing dump file $dumpfile.full failed.\n"; } # All done!