Tag: subversion

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!