Click here to Skip to main content
15,867,308 members
Articles / Operating Systems / Windows
Article

Automated Source Safe Backups

Rate me:
Please Sign up or sign in to vote.
4.56/5 (11 votes)
20 Feb 2001 266.5K   52   55
A scripted approach to automating Visual Source Safe backups

Automated Source Safe Backups

Recently I became tired of manually backing up a source safe database by going into the source safe administrator and going through the manual backup procedure. I decided to automate the process.

Goals

1. Automate the process so it occurs once a day.
2. Generate backup files that are identified by date (ie. '08-20-2000 Project Backup.ssa').
3. If possible don't resort to using any programs other than the built in NT utilities.

**NOTE!**

I solved these problems on Windows 2000 and everything works fine using the steps below. On windows NT 4 however there is one major problem, the 'at' utility for scheduling operations would not work for me, I tried it on several different computers and even though it appeared to schedule an operation it just would not run it when the time came. The exact same commands that work on windows 2000 do not work on NT 4. If someone knows how to get 'at' working then I would appreciate it!

Step 1

Create a batch file with the following text.

@ECHO OFF
@TITLE Backing up source safe databases<br>
FOR /F "tokens=2-4 delims=/ " %%i IN ('date /t') DO SET DATE=%%i-%%j-%%k
e:\source_safe-code\win32\ssarc -d- e:\backups\%DATE% General backup.ssa $/General
@ECHO Finished backups

Replace 'e:\source_safe-code' with the location of your source safe database directory.
Replace 'e:\backups' with the directory that you want to place the backed up projects into. 
*NOTE* if your source safe data is kept in a different directory than the 'data' directory inside of source safe you will need to tell ssarc this. Look up the documentation in the MSDN (see Further Reading at the bottom of this document)
Replace 'General backup.ssa' with the name of the file that you want to save the backups to (the file will be saved in the format '8-2000-99 name.ssa')
Replace the 'General' after the '$/' with the name of the project that you want to backup or just put '$/' to backup everything.

Save this batch file somewhere, I used the name 'ss_backup.bat'. Test the batch file by running it from the command line.

I'll explain the workings of the batch file later.

Step 2

To automate the running of the batch file I used a utility that comes with NT and 2000 called 'at'.

Make sure that the 'Schedule' service for NT or 2000 is running by going to the control panel->Services and finding the 'Schedule' service Make sure to set it up to startup automatically, otherwise when you reboot it will not be active.

Go to the command prompt and enter the command 'at'. If everything is going ok this should give you a list of recurring processes already set up (it may be an empty list).

Enter this command line, it will schedule the backups using the batch file you created earlier:

at 05:00:00 /interactive /every:M,T,W,Th,F,S,Su cmd /c e:\ss_backup.bat

Replace 05:00:00 with the time that you want to run the process.
Replace M,T,W,Th,F,S,Su with the times that you want to run the backups.
Replace e:\ss_backup.bat with the location that you saved the batch file from step 1.

Final Step

You should now be all set to go. The backups will be put into the directory that you specified and will take place. I have the backups taking place on a daily basis and then at the end of every week I archive the backups to CD. I Also added another line in the batch file that copies the backed up file to a remote drive for added redundancy.

It is probably also a good idea to add a periodic job to analyze the source safe database for errors. I have had inconsistencies in the database before, and it is a good idea to monitor for problems. Microsoft recommends running the analyze utility once a week. You can find more information at http://msdn.microsoft.com/library/techart/vssbest.htm. Make sure that no one is logged in and using the source safe database before running the 'analyze' utility! You can use the -x parameter for analyze to force users out.. but Microsoft does not recommend this.

Explanation of Batch File

The batch file is pretty simple. The only line that requires much explanation is:

FOR /F "tokens=2-4 delims=/ " %%i IN ('date /t') DO SET DATE=%%i-%%j-%%k

'FOR' is a built in NT/2000 command that allows you to process the output of file listings and text listings. The '/F' flag tells 'FOR' to process the immediate output of the command that is run, in this case the output of of 'date /t', which is the current date. 'tokens=2-4' tells 'FOR' to tokenize the output of date /t and grab tokens 2 through 4 and put them into variables starting at %%i (so the tokens can be referenced as %%i. %%j, %%k etc..) . The stuff after DO is executed after the tokenizing is finished and it assigns an environment variable 'DATE' with the tokens with dashes in-between them. In this case the tokens are the month-day-year.


This line also needs a little explanation

e:\source_safe-code\win32\ssarc -d- e:\backups\%DATE% General backup.ssa $/General

ssarc is the command line backup utility that comes with source safe, it is installed by default in the 'win32' directory of source safe. -d- tells it not to delete any of the files that it is backing up. The parameter after that is the name of the output file and the next parameter is the name of the SourceSafe project to backup.

@TITLE sets the title of the command line box that is created when this batch file is run.

Further Reading

Documentation for all of the source safe command line tools is available in the MSDN under Visual Studio Documentation -> Visual Source Safe Documentation -> Reference Guides -> Using the VSS command line.

http://msdn.microsoft.com/library/techart/vssbest.htm

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
Visual C++/Java programmer.

Comments and Discussions

 
GeneralRestore Pin
saintso31-Jul-05 18:13
saintso31-Jul-05 18:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.