This wide- and large- screen layout may not work quite right without Javascript.

Maybe enable Javascript, then try again.

Home Visual Source Safe

Example Automatic VSS Maintenance Script

If you want to closely examine the charts/pictures/code on this page but they are not easily viewable on your device, note the web address and return to view it later from a device with a larger display screen.

This material on VSS is an archive from fall 1998, about two decades ago. First I changed jobs so I no longer had any association with VSS. Then after a couple more years I changed careers completely so I wasn't associated with high tech at all. Then after even more years I retired altogether. I've left the VSS material on this site for use by others, even though I no longer remember exactly what it's about, or even understand some of it.

VSS continues to be used and to provide integration with other products, even though the VSS software product itself has been retired. Almost all VSS consulting services have disappeared. Microsoft Mainstream Support is no longer available for any version of VSS. And the end is near even for Microsoft Extended Support for VSS2005. As a result, roll your own support may become more important, and the experience with VSS related by these pages may turn out to be quite useful to some despite its great age.

This material reflects experience with VSS5. The user interfaces and the feature set in VSS6 were virtually identical, so almost all of this material continued to apply for several years. But I never had any detailed knowledge of the user interfaces or feature set of VSS2005, and so simply assumed most parts of this material still applied.

This script, which was used in production, is an implementation of automatic VSS maintenance.

This script is implemented with WinBatch. WinBatch is a third party tool that provides plenty of control structures, many built in functions including some utility functions not available in the base OS, keystroke stuffing, menu item invocation, and monitoring of window titles. It's thought this script could be easily ported to another language, even a simpler one that did not do keystroke stuffing, menu item invocation, or monitoring of window titles, for example the new Command Shell that first became available in Windows NT 4 accompanied by something like the NT Resource Kit.

;debug(@ON)
; Backup_vss.wbt
wwwnt32i=1
result=AddExtender("WWWNT32I.DLL")
if (result==@FALSE)
  wwwnt32i=0
endif

vssshare="%param1%"
vssloc="%param2%"
auto="%param3%"
backup=1
eject=1
Ticks = 10
if auto==""
  auto = 0
  warn=0
  shutdown=0
else
  auto = 1
  warn=1
  shutdown=1
endif
;vssshare = "VSS_Test"
;vssloc   = "d:\vss_test"

;Get and clean up the date
tdate = TimeDate()
gosub CLEAN_DATE

logfile = "c:\vss\tools\backup\logs\%vssshare%-%date%.log"

if (auto==@FALSE)
  ;Open Main Dialog
  while @TRUE
    gosub MAIN_DIALOG
    ;  Did we select Cancel?
    if ButtonPushed==9
      BoxOpen("","Shutting Down")
      Delay(1)
      BoxShut()
      exit
    endif
    if ButtonPushed==7 
      break
    endif
  endwhile;
endif

loghand = FileOpen(logfile,"WRITE")
tdate=TimeDate()
gosub CLEAN_DATE
FileWrite(loghand, "Starting Backup of %vssshare% on %tdate%")
FileWrite(loghand, "-----------------------------------------------------------------")

;Notify users database will be going down.
if warn
  tdate=TimeDate()
  gosub CLEAN_DATE
  FileWrite(loghand, "%time% : Warn users that database is going down.")
  ;RunWait(Environment("COMSPEC"), "/c net send /USERS %vssshare% will be going down in 5 minutes!")

  ;Sleep for 5 minutes
  tdate=TimeDate()
  gosub CLEAN_DATE
  FileWrite(loghand, "%time% : Sleeping for 5 minutes.")
  Delay(300)
endif

;Stop VSS Share to down database
if shutdown
  if wwwnt32i
    tdate=TimeDate()
    gosub CLEAN_DATE
    FileWrite(loghand, "%time% : Removing %vssshare% to shut down database.")
    result=wntShareDel("",vssshare,0)
    if (result==@FALSE)
      FileWrite(loghand, "%time% : Error removing %vssshare%, share not found.")
    endif
  else
    FileWrite(loghand, "%time% : Unable to remove %vssshare%, NT Network extender not loaded.")
  endif
endif

;Backup Database
if backup
  tdate=TimeDate()
  gosub CLEAN_DATE
  FileWrite(loghand, "%time% : Starting Backup of %vssshare%.")
  FileClose(loghand)
  loghand=0
  ;RunWait("ntbackup", "backup %vssloc% /e /v /d %vssshare% on %date% /b /hc:on /l%logfile%")
  ;Turn off Hardware compression to see if it speeds up backup
  Run("ntbackup", "backup %vssloc% /e /v /d %vssshare% on %date% /b /hc:on /l%logfile%")
  gosub CheckWindows
endif

;Eject Tape
if eject
  tdate=TimeDate()
  gosub CLEAN_DATE
  if !loghand then loghand = FileOpen(logfile,"APPEND")
  FileWrite(loghand, "%time% : Ejecting Tape.")
  RunWait("ntbackup", "eject")
endif

;Recreate VSS Share
if shutdown
  if !loghand then loghand = FileOpen(logfile,"APPEND")
  if wwwnt32i
    tdate=TimeDate()
    gosub CLEAN_DATE
    FileWrite(loghand, "%time% : Recreating %vssshare% to open database.")
    result=wntShareAdd("",vssloc,vssshare,0,-1)
    if (result==@FALSE)
      FileWrite(loghand, "%time% : Error creating %vssshare%.")
    endif
  else
    FileWrite(loghand, "%time% : Unable to recreate %vssshare%, NT Network extender not loaded.")
  endif
endif

if !loghand then loghand = FileOpen(logfile,"APPEND")
tdate=TimeDate()
FileWrite(loghand, "-----------------------------------------------------------------")
FileWrite(loghand, "Backup of %vssshare% on %tdate% complete")
FileClose(loghand)
exit

:CLEAN_DATE
date = tdate
time = strsub(date,14,strlen(date)-14)
date = strsub(date,5,strlen(date)-5)
date = strreplace(date,"/","-")
date = strtrim(date)
index = strscan(date," ",0,@FWDSCAN)
date = strsub(date,1,index-1)
if (strlen(date) < 8) then date = "0%date%"
return

:MAIN_DIALOG

VSSBackupFormat=`WWWDLGED,5.0`

VSSBackupCaption=`VSS Backup`
VSSBackupX=10000
VSSBackupY=10000
VSSBackupWidth=195
VSSBackupHeight=80
VSSBackupNumControls=10
              
VSSBackup01=`2,3,102,DEFAULT,STATICTEXT,DEFAULT,"VSS Share Name"`
VSSBackup02=`70,2,120,DEFAULT,EDITBOX,vssshare,""`
VSSBackup03=`2,17,102,DEFAULT,STATICTEXT,DEFAULT,"Physical Location"`
VSSBackup04=`70,16,120,DEFAULT,EDITBOX,vssloc,""`
VSSBackup05=`12,31,102,DEFAULT,CHECKBOX,warn,"Warn Users",1`
VSSBackup06=`12,45,102,DEFAULT,CHECKBOX,shutdown,"Stop/Start Database",1`
VSSBackup07=`120,31,102,DEFAULT,CHECKBOX,backup,"Backup Database",1`
VSSBackup08=`120,45,102,DEFAULT,CHECKBOX,eject,"Eject Tape",1`
VSSBackup09=`58,63,64,DEFAULT,PUSHBUTTON,DEFAULT,"&Ok",7`
VSSBackup10=`126,63,64,DEFAULT,PUSHBUTTON,DEFAULT,"&Cancel",9`

ButtonPushed=Dialog("VSSBackup")

return

:CheckWindows
while WinExist("Backup") == @TRUE
  If WinExist("Insert Tape") == @TRUE 
    SendKeysTo("Insert Tape", "!n")
    Delay(Ticks)
    tdate=TimeDate()
    gosub CLEAN_DATE
    if !loghand then loghand = FileOpen(logfile,"APPEND")
    FileWrite(loghand, "%time% : ERROR!! No TAPE in drive!")
    FileClose(loghand)
    loghand=0
    break
  Else
    Delay(Ticks)
  Endif
endwhile

return


Location: (N) 42.67995, (W) -70.83761
 (North America> USA> Massachusetts> Boston Metro North> Ipswich)

Email comments to Chuck Kollars
Time: UTC-5 (USA Eastern Time Zone)
 (UTC-4 summertime --"daylight saving time")

Chuck Kollars headshot Chuck Kollars' other web presences include Chuck's books and Chuck's movies.

You may also wish to look at Dad's photo album.

All content on this Personal Website (including text, photographs, audio files, and any other original works), unless otherwise noted on individual webpages, are available to anyone for re-use (reproduction, modification, derivation, distribution, etc.) for any non-commercial purpose under a Creative Commons License.