Click here to Skip to main content
Email Password   helpLost your password?

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

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
QuestionVery helpfull, thanks
enamur
22:58 26 Nov '07  
backup system is working fine, but how can i restore the file? Can anyone help me, please!

Enamur
GeneralI use Code Co-op from Reliable Software (VSS == dog)
matt2000
7:39 28 Aug '07  
We could not get it to work reliably with our remote development team. The great thing about Code Co-op is that its server-less, strictly an email based version control system. It will auto-merge multiple files. Fast and flawless.

Stay away from VSS if you can. You would do yourself and your organization a big favor by looking into Code Co-op and adopting it.

GeneralRe: I use Code Co-op from Reliable Software (VSS == dog)
sledhed
12:28 24 Sep '07  

matt2000 wrote:
We could not get it to work reliably with our remote development team. The great thing about Code Co-op is that its server-less, strictly an email based version control system. It will auto-merge multiple files. Fast and flawless.

Stay away from VSS if you can. You would do yourself and your organization a big favor by looking into Code Co-op and adopting it.

Confused Off-topic and not very useful comment. This is not an evaluation forum for VSS nor a forum for promoting what you are using. VSS has its problems yes, but this kind of article is good for those of us using it, and there are a lot of us out here.
GeneralPassing the Admin password
DimondWolfe
12:57 13 Jun '07  
If your VSS admin has a password, how would you pass that in through the batch file? It's great having a batch file to do this, but to automate it, we'll need to be able to avoid having it ask for the password when it launches.

Other than that, this is a GREAT article! Smile

You know what ol' Jack Burton says at a time like this...

GeneralRe: Passing the Admin password
DimondWolfe
13:09 13 Jun '07  
I figured it out. It appears that, if you have a "special character" in the password, you need to put quotes around it. So the line would read:

e:\source_safe-code\win32\ssarc -d- -YAdmin,"pass^word" e:\backups\%DATE% General backup.ssa $/General

KRP

You know what ol' Jack Burton says at a time like this...

Generalpressing ctrl-c in the middle of a backup operation
Sameer Alibhai
12:43 11 Jun '07  
Be careful.. I found out (the hard way), that if you use ssarc -d (instead of -d-) that it will actually not only DELETE your data from sourcesafe, but also, it will stop creating the backup file on disk and you will lose your data from both places.....!



GeneralPowershell version of automated source safe maintenance/backups
Kevin Hammond
11:34 18 Apr '07  
Here is a link to a PowerShell based VSS maintenance scripts that perform automated backups among other things.

http://www.codeplex.com/PSvss[^]


GeneralRestore
saintso
19:13 31 Jul '05  
Dear all

what are the restore methods available in VSS ?

After restore the archive file succefully, then open the DB, there are no file has been restored into DB.
GeneralCheck-in comments...
sgoks
20:18 25 Feb '05  
How do I make the Check-in comments mandatory while checking in files into Visual Source Safe?

asdf
Generalnice job
Tim Kohler
9:28 1 Feb '05  
Nice job and documentation.

thanks!
GeneralUK Date Formats
James H
3:32 12 Oct '04  
This didn't seem to work quite right for me - think it is because of UK dates - I changed the FOR bit to

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

This make date of format YYYYMMDD if incoming date was UK DD/MM/YYYY

Otherwise this is a great tip
GeneralTurn off interactive mode???? -i-
Anonymous
3:56 22 Sep '03  
Using -i- seems to default the "Continue (y/n)?" answer to "N".

I used "-i-y" and it seems to work. This article doesn't use the "i" switch at all, I wonder if I even need to turn off interactive mode?




Generaluse inbuilt sheduled task functionality
panache
5:06 21 May '03  
I think, instead of going for 'at' u can go for control panel->scheduled task and add the batch file as a task at particular time.
May work on nt also (did not try myself although)
GeneralVSS backup over 128 characters
Nemesis_DBA
9:20 3 Mar '03  
I tried to back up VSS, but you cannot backup a file that has a file path over 128 characters.

Is there any way to back up VSS when a web project has a deployment file path over 128 characters.

Thanks
GeneralRe: VSS backup over 128 characters
Mahasen Bandara
18:24 12 Jan '04  
simple - change the directory in the previous line Big Grin
worked for me
GeneralBackup Methods
Anonymous
1:57 6 Aug '02  
what are the backup methods available in VSS?
Generalvbs version
Anonymous
1:00 25 Jul '02  
hi,

here's a .vbs version of the batch Smile


+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

'backup VSS database to a file named "day of week".ssa
'this VSS backup is launched every day and is one week modulo : monday.ssa (07/01/2002) replace monday.ssa (07/08/2002)
'this VSS backup is daily scheduled at 1AM, and general ntbackup (daily too) including this file is scheduled at 3AM
'task scheduler of NT4 SP6 ie6 and W2K can launch .vbs directly

'create archive filename
Dim archive_filename, cmd
archive_filename = "E:\dev\VSSBackup\" & WeekDayName(DatePart("w",Now)) & ".ssa"

'create objects
Set fso = CreateObject("Scripting.FileSystemObject")
Set WshShell = Wscript.CreateObject("Wscript.Shell")

'delete old file if exists
If (fso.FileExists(archive_filename)) Then
fso.DeleteFile(archive_filename)
End If

'go go go
cmd = """E:\Program Files\Microsoft Visual Studio\Vss\Win32\Ssarc.exe""" & " -yAdmin,passwd -d- -i- -s" & """E:\dev\VWork\Vss""" & " " & archive_filename & " $/"
WshShell.Run cmd, 1, TRUE

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

see u
benoit Guyon - Dataset.fr
GeneralSourcesafe backups
Esther Queen
6:45 24 Jul '02  
from the batch file that backs up a sourcesafe database automatically into an archive file...what is really included in that saved archive file? is it the entire data directory, or just the specific projects in the database?
in other words, if just one of my projects goes in the dumps and i need to restore it, will the archive file let me do that? AND restore the entire data directory if needed?
GeneralCopying a project archive to disk
Anonymous
9:25 15 Apr '02  
I'm looking for a way to copy my whole project archive out of VSS onto a CD.
As of right now I see no functionality that allows such a move.
Can anyone help?
Generala batch file to put files to floppy
pooky
5:52 15 Mar '02  
Gang,
I know how to do simple batch files. The problem I'm having is trying to get 2 types of files onto the same floppy. One type has a .hdr extension and the other has a .dat extension. The two types ALWAYS come in pairs and one pair must be renamed and then MOVED to the floppy before the next pair is processed onto a new floppy. The file pairs arrive to the directory via ftp. Often the directory has more than one pair that must be processed.


GeneralSource Safe sharing
sreejith
3:28 14 Mar '02  
we want to use our project from the source safe db,by checking out each user's requiured forms and work on that forms only.Nobody else get the edit option other than the checked out user.WE have created the VSS DB and added the project ,Created different users and checked out seperately but the readonly option in forms is not coming properly
GeneralRe: Source Safe sharing
Anonymous
9:54 14 Aug '02  
In SourceSafe Administrator, Tools, Options, General, make sure Allow Multiple Checkouts is unchecked.   Then enable project security in the next tab.

Eideto
Generalremote VSS
Guljeet Nagpaul
3:42 25 Feb '02  
Hi all
I want the onsight people to access my VSS server(in INDIA) from there , now this using internet is going to take ages to download the files.
Instead i was wondering if by some way we have to 2 VSS servers working at both onsight and offshore and both these servers be synchronised automatically.
OR if by some script (batch process) we could send a copy of al the changed files and it updates there VSS by these new files
I would be obliged if i can get a solution .
GeneralRe: remote VSS
Kishore27
0:19 5 Dec '02  
Use Source Offsite Tool WebSite www.sourcegear.com
Cool
Generalremote VSS
Anonymous
3:36 25 Feb '02  
Hi


Last Updated 21 Feb 2001 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2010