Next post: Moving from svn to git, and fixing line-endings along the way

Downloading all revisions from a remote subversion repo

I had several svn repos online, and wanted to create complete backups containing all revisions. So, I wrote a Python script to automate the process. (It looks like there's a project rsvndump that does something similar, but I knew that what I wanted could be done in a few lines of Python.)

First, set the values in the first few lines to point to your repo, then run the script.
url = 'https://url.of.repo/svn/'
output = '/full/path/to/desired/output'
username = 'user.name'

import os, subprocess, shutil
from os.path import join, exists

def runwithshell(listArgs):
  print('  '.join(listArgs))
  popen = subprocess.Popen(listArgs, shell=True, stdout=subprocess.PIPE)
  stdout = popen.communicate()[0]
  return stdout.rstrip(), popen.returncode

def run_assertsuccess(cmd):
  assert '|' in cmd
  cmd = cmd.split('|')
  stdout, ret = runwithshell(cmd)
  assert ret == 0

def go():
  assert exists(output)
  os.chdir(output)
  run_assertsuccess('svnadmin|create|lrepo')
  if sys.platform.startswith('win'):
    assert ':' in output, 'full path needed'
    fout = open('lrepo/hooks/pre-revprop-change.bat', 'w')
    fout.write('')
    fout.close()
  else:
    assert output.startswith('/'), 'full path needed'
    fout = open('lrepo/hooks/pre-revprop-change', 'w')
    fout.write('#!/bin/sh\nexit 0;')
    fout.close()
    run_assertsuccess('chmod|+x|localrepos/hooks/pre-revprop-change')
    
  run_assertsuccess('svnsync|init|--username|' +username + 
    '|file:///' + output + os.dirsep + 'lrepo|'+url)
  run_assertsuccess('svnsync|sync|--username|' + username + 
    '|file:///' + output + os.dirsep + 'lrepo')

def createExportDump():
  assert exists(output)
  os.chdir(output)
  run_assertsuccess('svnadmin|dump|.' + os.dirsep + 
    'lrepo|--incremental|>|out.dump')

if __name__=='__main__':
  go()
  createExportDump()
  print('saved to out.dump')


Later, to restore from the dump, you can run from a console,
svnadmin create newrepo
svnadmin load ./newrepo < out.dump
References: How do I download my Subversion history