Automate backing up visualsvn repositories with Windows Powershell

To backup your VisualSVN repositories, you will need the following

  1. Windows powershell installed and configured to allow scripts to run. If you’re unsure of how to enable powershell scripts to run locally, see this superuser thread
  2. A place to backup files. I have mine synced to a local folder, which is then synced to OneDrive

Step one. Create a text file and change the extension to .ps1

The file would be something like VisualSVNscript.ps1

Step two. Add the following lines to the file

#Name of project1
Remove-Item -Recurse -Force <PUT YOUR PROJECTS DESTINATION DIRECTORY HERE>
svnadmin.exe hotcopy <PUT YOUR PROJECTS SOURCE DIRECTORY HERE> <PUT YOUR PROJECTS DESTINATION DIRECTORY HERE>
#Name of project2
Remove-Item -Recurse -Force <PUT YOUR PROJECTS DESTINATION DIRECTORY HERE>
svnadmin.exe hotcopy <PUT YOUR PROJECTS SOURCE DIRECTORY HERE> <PUT YOUR PROJECTS DESTINATION DIRECTORY HERE>
#Name of project3
Remove-Item -Recurse -Force <PUT YOUR PROJECTS DESTINATION DIRECTORY HERE>
svnadmin.exe hotcopy <PUT YOUR PROJECTS SOURCE DIRECTORY HERE> <PUT YOUR PROJECTS DESTINATION DIRECTORY HERE>
#Name of project4
Remove-Item -Recurse -Force <PUT YOUR PROJECTS DESTINATION DIRECTORY HERE>
svnadmin.exe hotcopy <PUT YOUR PROJECTS SOURCE DIRECTORY HERE> <PUT YOUR PROJECTS DESTINATION DIRECTORY HERE>

You will need to do this PER project! Hotcopy can only copy to an empty directory, so we delete the contents of the directory first then copy the newest code to the directory. Save the file and exit

Step three. Use Windows Task Scheduler to run the script automatically for you.

  1.  Press Start and start typing “Task Scheduler”. Click on it.
  2. Click create basic task, name the task “VisualSVN backup” or anything you like and select desired frequency
  3. For a command enter in “powershell -file <pathtoscript>” and click Finish

That’s it! Your VisualSVN projects will now automatically be backup for you!

2 comments for “Automate backing up visualsvn repositories with Windows Powershell

  1. bahrep
    March 3, 2017 at 6:57 am

    Hello Evan,
    Thank you for this post!

    I would remove `Remove-Item -Recurse -Force` commands from the script. There is a chance that a user unintentionally confuses and and the script will remove the repositories instead of making backup.

    BTW, VisualSVN Server 3.6 will introduce a built-in backup solution[1] and it is going to be released in short time. I guess that you might want to try Release Candidate build of the upcoming version. You can download it at https://www.visualsvn.com/server/download/pre-release/

    [1]: https://twitter.com/visualsvn/status/837346777808285697

    • Evan Parsons
      March 3, 2017 at 12:11 pm

      Hey bahrep,
      The reason I force removal is because I was getting an error message saying that the directories were not empty. But I completely agree with the potential for a user wiping their own repository, which is why in my example I caps-locked everything.

      I’ll have a look at the release candidate of VisualSVN, that feature looks pretty slick/easy

Leave a Reply

Your email address will not be published. Required fields are marked *