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 = ''

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)
  if sys.platform.startswith('win'):
    assert ':' in output, 'full path needed'
    fout = open('lrepo/hooks/pre-revprop-change.bat', 'w')
    assert output.startswith('/'), 'full path needed'
    fout = open('lrepo/hooks/pre-revprop-change', 'w')
    fout.write('#!/bin/sh\nexit 0;')
  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)
  run_assertsuccess('svnadmin|dump|.' + os.dirsep + 

if __name__=='__main__':
  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