Ticket #6 (closed enhancement: fixed)
[Patch] Subversion incremental backups
| Reported by: | rosskevin | Owned by: | |
|---|---|---|---|
| Priority: | major | Milestone: | v1.02 |
| Version: | 1.01 | Keywords: | |
| Cc: |
Description
I have adapted some perl code to utilize subversion incremental backups to the current s3napback code. I am still testing it, but it would appear from the outside to be a logical and stable method. Our subversion repositories are several gigabytes so full dumps is not a reasonable option for us.
I am locally using this with a <SubversionIncremental?> tag, but it would probably make sense if the code is altered a bit to recognize Diffs vs. the absence of a Diff config and replace the Subversion tag.
Code below:
#
# Inspired by from http://le-gall.net/pierrick/blog/index.php/2007/04/17/98-subversion-incremental-backup
# Adapted to s3napback by Kevin Ross - metova.com
#
sub backupSubversionIncremental {
my ( $name, $frequency, $phase, $diffs, $fulls ) = @_;
if ( ( $yday + $phase ) % $frequency != 0 ) {
print "Skipping $name\n";
next;
}
my $difffile = $name . ".diff";
$difffile =~ s/\_/g;
$difffile = $diffdir . $difffile;
# initialize the last saved revision as -1, that way on the first pass it is simply incremented to 0 (the first revision).
my $lastSavedRevision = -1;
# check the time on any existing diff file to see if this was already done today.
my $sb = stat($difffile);
if ( defined $sb ) {
my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $diffyday, $isdst ) =
localtime( $sb->mtime );
if ( $diffyday == ( $yday + $phase ) ) {
print "Skipping $name was already backed up today\n";
next;
}
# The diff file exists and we nee to run, so read the last saved revision from the file
open( LAST_SAVED_REVISION, '<', $difffile );
$lastSavedRevision = <LAST_SAVED_REVISION>;
chomp $lastSavedRevision;
close(LAST_SAVED_REVISION);
}
# get informed of the current last revision (head)
my $headRevision = svnlook youngest $name;
chomp $headRevision;
my $cycles = $fulls * ( $diffs + 1 );
my $cyclenum = ( ( $yday + $phase ) / $frequency ) % $cycles;
my $type = "DIFF";
if ( $cyclenum % ( $diffs + 1 ) == 0 $lastSavedRevision < 0) { $type = "FULL";
# remove the diff file, we want to do a full backup.
unlink $difffile;
}
# if ( $type == "DIFF" && $lastSavedRevision == $headRevision ) {
#
# # of course, if the head is not younger than the last saved revision it's useless to go on backing up.
# next;
# }
# if the last saved is 1000 and the head is 1023, we want the backup from 1001 to 1023
my $fromRevision = $lastSavedRevision + 1;
my $toRevision = $headRevision;
my $datasource = "svnadmin dump -q -r$fromRevision:$toRevision --incremental $name | gzip";
my $bucketfullpath = "$bucket:$name-$cyclenum-$type";
print "Subversion $name -> $bucketfullpath\n";
sendToS3( $datasource, $bucketfullpath );
# Save last revision to the diff file so we know where to pick up later.
if ( !$opt{t} ) {
open( LAST_SAVED_REVISION, '>', $difffile );
print LAST_SAVED_REVISION $toRevision, "\n";
close(LAST_SAVED_REVISION);
}
}
Attachments
Change History
Changed 4 years ago by rosskevin
-
attachment
s3napback2.pl
added
My full file. Apologies, but I had to autoformat it for my own sanity.
