Posted By

spreelanka on 11/09/09


Tagged

svn subversion perl obliterate


Versions (?)

remove sensitive info from a subversion repository


 / Published in: Perl
 

I recently had to remove some files from a svn repo. should work pretty much out of the box, just fill in blatantly exampleish text and read the comments

  1. #!/usr/bin/perl
  2. use strict;
  3. my $svn_repo='local/path/to/repo';
  4. my $f='full_repo_dump';
  5. my $pattern='foldername/otherfoldername/offendingFileOrDirectory';
  6. `svnadmin dump $svnrepo > $f`;
  7.  
  8. open I,'<'.$f;
  9. open O,'>'.$f.'_cleaned';
  10.  
  11. my $c=0;
  12. my $i=1;
  13. while($_=<I>){
  14. while(/^Node-path: $pattern/){#this is what we want to remove
  15. $_=<I>;
  16. while(!/^Node-path/){
  17. $_=<I>;
  18. exit unless($_); #we are out of file to read, quittin time(this is likely bad form)
  19. }
  20. }
  21. ###just a workaround for large repo dumps and status bar type stuff
  22. if($c eq 0){
  23. $c=100001;
  24. print ++$i,"\n" ;
  25. }
  26. if($i%1000 eq 0){# also if your repo dump>2gb or so it will crash. this is not very precise, but it worked in my case
  27. close O; #anyway, you get the point, close and open as append only to flush whatever file buffers perl's using
  28. open O,'>>'.$f.'_cleaned';
  29. }
  30. $c--;
  31. ###
  32. print O $_;
  33. }
  34.  
  35. `svnadmin create freshly_cleaned_repo`;
  36. `svnadmin load freshly_cleaned_repo < $f`;
  37. #you should also `svnadmin dump $svnrepo -r0 > hey_whats_my_uuid`, look inside it for your uuid and
  38. # then `svnadmin setuuid freshly_cleaned_repo this-is-your-really-long-uuid-here`
  39. # pulling and setting the uuid could be automated

Report this snippet  

You need to login to post a comment.