A while ago, I decided that I needed to have a better backup solution for my file server. After doing some research on various systems, I let my inner programmer take over – in addition to my desire to NEVER LOSE ANYTHING – and I defaulted to use SVN.
I was using a Windows machine as my file server – so I wrote some batch files. I also had SVN installed on the machine. The final touch was adding scheduled tasks.
The setup includes a computer that is always on with windows, svn command line, and 5 directories to monitor for backups.
First thing’s first, do an SVN Checkout
The very first thing I did was make an SVN checkout in all of the five parent directories. This way I can continue to use SVN add, svn commit without any other interaction. Don’t worry, we’ll use recursion!
Create the full list of backups
So, first thing’s first: Create the list of directories that need to be monitored. I made them in this txt file named ‘svndirectories.txt’:
1 | D:\pictures D:\storage\videos\misc D:\storage\files\art D:\storage\files\NeverAgain D:\storage\files\Therapee |
Note, all of them are separated by a space. This becomes important in our next batch script.
Schedule the SVN Add
I added an SVN Add batch script at Midnight on sundays. Actually, there are two batch files. I made them separately so that I could invoke a scheduled task – but also run the “add” by hand if need be.
The first file, addsvn.bat:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | @echo off REM ------------------------------------------------------------------ REM - forces adds on all svn files REM ------------------------------------------------------------------ :START REM - Get file to process set direct=%1 echo %direct% echo. :SVNADD svn add --force %direct%\* :NEXTFILE shift if "%1"=="" goto END goto START :END |
That will force an add of each file passed in on the command line. Then, the batch file that I made to be ran from the scheduler will read in the folders from the text file, and run this script. Here is ‘scheduled_addsvn.bat’:
1 2 3 4 5 6 7 8 |
Theoretically, I could have called it with the entire line of files after it, but I wanted to call them separately to handle errors better.
After all of these have been added, lets move on…
Schedule SVN Commit
Just in case I made a huge addition of files, I let an hour pass between scheduled add and scheduled commits. Additionally, I ran the commit every day instead of every week. I figured I’d make more changes than I would make additions.
So first, read in all of the directories again and run the commit. Then, the file to schedule. These are pretty much similar, just different commands:
commitsvn.bat:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | @echo off REM ------------------------------------------------------------------ REM - commits all SVN changes REM ------------------------------------------------------------------ :START REM - Get file to process set direct=%1 echo %direct% echo. :SVNCOMMIT svn commit --message="Auto Backup" %direct%\* :NEXTFILE shift if "%1"=="" goto END goto START :END |
scheduled_commitsvn.bat:
1 2 3 4 5 6 7 8 |
This has worked out pretty well for me. If you see anything I could do better, please let me know!

aww, cute little batch files *snicker*.
good idea. I thought of this exact thing, never tried it though. I was thinking it’d be awesome to make a file system in linux that uses svn (using FUSE, similar to how the GmailFS works). My main concern was binary files, as I don’t think there’s an efficient way to deal with those. Awesome that you did it though.
I know this is an old entry, but I was just wondering (if you remember) if you set this to be a scheduled task on your windows machine by chance?
I did something similar–backing up SVN code through a Windows machine and into TFS. The batch runs great when i execute manually, but when I’m checking my history in TFS, it indicates that the check-in doesn’t happen when I’m not logged into the box.
Just wondering–i’m trying to find the reason & don’t know if it’s the SVN export or the TFS check-in that isn’t happening.
Thanks.
@Jill: I didn’t run into that problem before… but when you create a scheduled task, one of the advanced options is choosing a login profile. You may want to see if you can specify an account that way – just in case…
@Jill: Yah I set it up as a scheduled task – running as my user account.
File backups do not need to be a task. A thoughtful backup cron will run for years.
Can i get my destination automatically updated through scheduler when the source is on another pc witihin a network.If possible plz rply me on email mentioned Thnx in Advamce
how can i take back up of only the files that have been updated rather than taking backup of whole data?
This will always be only the updated files. SVN will recognize the updates and back those up.
svn 1.7 has broken your script, would you please shed some light?
svn: E200009: Commit failed (details follow):
svn: E200009: ‘D:\test_auto_sync\*’ is not under version control