::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :: NAME: VSSMaint.cmd :: DATE: October 20, 2003 :: VERSION: 1.0 :: AUTHER: Assad Chaudhry :: WEBSITE: www.assad.ca :: EMAIL:
This e-mail address is being protected from spambots. You need JavaScript enabled to view it
:: DESCRIPTION: :: :: Visual SourceSafe Maintenance Script :: ==================================== :: :: Script command syntax and options :: vssmaint [/?][-copy] :: :: /? : Outputs the Help Section :: -copy: If optional argument -cOPY is used the following tasks are performed: :: (a) Make a local copy of the database under data folder. :: (b) Rename the database backup folder to data.bak0 :: (c) Copy the Database to backup folder data.bak :: :: :: Script performs routine maintenance and visual sourcesafe database backup.A log file :: listing the output of all actions taken in this script(vssmaintvssmaint-<Date>.log) is :: generated.If the script is run more than one in one day, the log file is appended.email :: the logfile to VSS administrator. :: :: A) The VSS database is locked :: :: B) The network drive is unshared and reshared after all task ate complated. :: :: C) If optional argument -copy is provided, copy the data folder as data.bak before :: analyze utility is exectued. :: :: D) Analyzing the data folder to look for signs of database corruption due :: to network or operating system problems and fixing the errors (using VSS Analyze :: utility) :: The Analyze utility is exextued up to three times (if any problem found) to correct :: problems. (Analyze utility generates its log info in databackupanalyze.log,which is also :: copied to a log file generated by this script) :: :: E) Archiving the database (using SourceSafe achieve utility). :: If Archive switch is active (file archive_on is present) do archive otherwise skip. :: Latest 5 copies of previous archive files are maintained on local drive. It would :: be wise to have weekly tape backup incase the local drive failure. :: The root folder where the backups are stored is ..archivebackups and each archive :: file is stored in a seperate folder named as backup.bak0... backup.bak5, where :: backup.bak0 folder contains the latest. :: :: F) Cleaning the "Temp" folder (VSS usually places files in its Temp folder while :: running, and deletes them before quitting. Some circumstances, such as having to :: restart, can cause files to remain in the Temp folder a waste of disk space). :: Empty the temp folder (path specified in srcsafe.ini) :: :: G) Send emails or Net Send Notification to Administrator and attach log files as body. :: :: ============================================================ :: History: DATE VERSION COMMENTS :: Oct 20,2003 1.0 (Initial Version) Created by Assad Chaudhry :: :: ============================================================ :: Disclaimer :: ========== :: The free software programs/documentation including this script provided by assad.ca may be freely :: distributed, provided that no charge above the cost of distribution is levied, and that the :: disclaimer below is always attached to it. :: :: The programs are provided as is without any guarantees or warranty. Although the author has :: attempted to find and correct any bugs in the free software programs, the author is not :: responsible for any damage or losses of any kind caused by the use or misuse of the programs. :: The author is under no obligation to provide support, service, corrections, or upgrades to the :: free software programs. :: ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
@ECHO OFF if /i %1.==/?. GOTO HELP ::if /i %1.==-help. ( :: GOTO HELP ) ::else ( :: set adminpasswd=%1 :: )
:: Capturing and setting Date & Time parameter FOR /F "tokens=2-4 delims=/ " %%i IN ('date /t') DO SET DATE=%%i-%%j-%%k For /F %%l IN ('Time /T') Do SET TIME=%%l
@ECHO ON
:: ////////////////////////////// :: //////////////////////////////
set sharename=vsssharefolderfolder
:: ADMIN NAME or Email addresses if email is sent instead of netsend notification :: ASSAD=Assad Chaudhry & PETER=Peter set VSSAdmin=localhost
set VSSBackupAdmin=localhost
set adminpasswd=test
set VSSadminEmail="
This e-mail address is being protected from spambots. You need JavaScript enabled to view it
" set VSSBackupAdminEmail="
This e-mail address is being protected from spambots. You need JavaScript enabled to view it
"
set MailServer=mail.abcompany.com set MailSubject="VSS SCRIPT"
:: SOURCESAFE DATABASE LOCATION (LOCAL) & Drive set basedir=C:VSSTestDatabase
:: Root for admin script , either drive letter or path to a folder set OutPutLocation=C:VSSScriptOutput
:: ANALYZE & ARCHIVE PROGRAM LOCATION set analyzePgm=G:PROGRA~1MICROS~3VSSwin32analyze.exe
set archivePgm=G:PROGRA~1MICROS~3VSSwin32ssarc.exe
:: ////////////////////////////// :: //////////////////////////////
set localdatadir=%basedir%data
:: VSS Maintainance Logfiles Folder LOCATION set vssmaintfolder=%OutPutLocation%vssmaint :: ARCHIVE BACKUP Folder LOCATION set arcbackupdir=%OutPutLocation%archivebackupsbackup
:: LOGFILE path (PRODUCED BY THIS SCRIPT) set logfile=%vssmaintfolder%vssmaint-%DATE%.log set acrlogfile=%vssmaintfolder%archive-%DATE%.log
:: TEMP DIR LOCATION (specified in srcsafe.ini) set tempdir=%basedir%temp
set vsslockfile=%localdatadir%loggedinadmin.lck set unlockDB= set copyflag= set archiveoff=
if /i %1.==-copy. set copyflag=1 cd /d %~dp0 time/t >> %logfile%
if NOT exist %vssmaintfolder% md %vssmaintfolder%
echo UNSHARING %sharename% >> %logfile% call :unShareVSS
:: LOCK THE DATABASE ECHO CHECKING DATABASE LOCK >>%LOGFILE% if NOT exist %vsslockfile% ( echo DB IS NOT LOCKED>>%LOGFILE% echo LOCKING DATABASE>>%LOGFILE% set unlockDB=1 echo.>%vsslockfile% ) else ( echo DATABASE IS ALREADY LOCKED >>%LOGFILE% set unlockDB=1 )
:: IF OPTIONAL ARGUMENT -COPY IS USED COPY THE DATA FOLDER if defined copyflag ( ECHO COPYING BACKUPS >>%LOGFILE% :: make copy of data directory :: note:verify enough free space if exist %localdatadir%.bak0 echo DATA.BAK0 EXIXTS - REMOVING FOLDER DATA.BAK0>>%LOGFILE% if exist %localdatadir%.bak0 rd /s/q %localdatadir%.bak0 :: iF it's a file if exist %localdatadir%.bak0 echo DATA.BAK0 EXISTS - REMOVING FILE DATA.BAK0>>%LOGFILE% if exist %localdatadir%.bak0 del /f %localdatadir%.bak0 if exist %localdatadir%.bak echo DATA.BAK EXISTS - RENAMING FOLDER DATA.BAK TO DATA.BAK0>>%LOGFILE% if exist %localdatadir%.bak ren %localdatadir%.bak data.bak0 :: iF it's a file if exist %localdatadir%.bak echo DATA.BAK ESISTS - DELETE FILE DATA.BAK>>%LOGFILE% if exist %localdatadir%.bak del /f %localdatadir%.bak
echo xcoping from %localdatadir% -TO- %localdatadir%.bak>>%logfile% xcopy %localdatadir% %localdatadir%.bak /e )
:: RUN ANALYZE :: -----------
:: Empty or rename the databackup directory. Otherwise, analyze fails. if exist %localdatadir%backup del /f /q %localdatadir%backup for %%i in (0 1) do if exist %localdatadir%backup.%%i del /f /q %localdatadir%backup.%%i for %%i in (0 1) do if exist %localdatadir%backup.%%i rd /s /q %localdatadir%backup.%%i
:::: DOING FIRST ANALYZE echo Beginning first ANALYZE>>%logfile% time/t >> %logfile% %analyzePgm% %localdatadir% -v4 -f -i- ECHO ANALYZE.LOG FILE >>%LOGFILE% ECHO ======STARTING ANALYZE====== >>%LOGFILE% type %localdatadir%backupanalyze.log>>%logfile% ECHO =======ANALYZE ENDS======= >>%LOGFILE%
:::: if ANALYZE FINDS PROBLEM CONTINUE OTHERWISE GOTO :ARCHIVE if exist %localdatadir%backupanalyze.log ( find "Found" %localdatadir%backupanalyze.log>nul || goto archive ) :::: SECOND RUN DOING ANALYZE echo Errors found. Doing 2nd analyze>>%logfile% ren %localdatadir%backup backup.0 time/t >> %logfile% %analyzePgm% %localdatadir% -v4 -f -i- -c -d ECHO ANALYZE.LOG FILE SECOND ATTEMPT>>%LOGFILE% ECHO ======STARTING ANALYZE====== >>%LOGFILE% type %localdatadir%backupanalyze.log>>%logfile% ECHO =======ANALYZE ENDS======= >>%LOGFILE%
:::: if ANALYZE FINDS PROBLEM CONTINUE OTHER GOTO :ARCHIVE if exist %localdatadir%backupanalyze.log ( find "Found" %localdatadir%backupanalyze.log>nul || goto archive )
:::: SECOND RUN DOING ANALYZE ECHO Errors found. Doing 3rd ANALYZE>>%logfile% ren %localdatadir%backup backup.1 time/t >> %logfile% %analyzePgm% %localdatadir% -v4 -f -i- -c -d ECHO ANALYZE.LOG FILE >>%LOGFILE% ECHO ======STARTING ANALYZE====== >>%LOGFILE% type %localdatadir%backupanalyze.log>>%logfile% ECHO =======ANALYZE ENDS======= >>%LOGFILE%
:archive
if not exist run_archive_on ECHO Archieve Process is bieng Skipped >>%LOGFILE% if not exist run_archive_on goto UNLOCKVSS
:: ARCHIVE :: ----------- :: BACKUP OF ARICHIVES :: Maintain last three archive files as backup :: arcbackdir = 1st backup, archbackdir.bak = 2nd last backup, archbackupdir.bak0 last backup (3rd) :: note:verify enough free space
if exist %arcbackupdir%.bak5 rd /s/q %arcbackupdir%.bak5 if exist %arcbackupdir%.bak4 move %arcbackupdir%.bak4 %arcbackupdir%.bak5 if exist %arcbackupdir%.bak3 move %arcbackupdir%.bak3 %arcbackupdir%.bak4 if exist %arcbackupdir%.bak2 move %arcbackupdir%.bak2 %arcbackupdir%.bak3 if exist %arcbackupdir%.bak1 move %arcbackupdir%.bak1 %arcbackupdir%.bak2 if exist %arcbackupdir%.bak0 move %arcbackupdir%.bak0 %arcbackupdir%.bak1 if not exist %arcbackupdir%.bak0 md %arcbackupdir%.bak0 :: RUN ARCHIVE del /s %acrlogfile% ECHO =======STARTING ARCHIEVE=======>>%LOGFILE% ECHO See archieve.log ( %acrlogfile% ) for details.>>%LOGFILE% ECHO ======ARCIVE.LOG START [%DATE%][%TIME%]====== >>%acrlogfile%
%archivePgm% -d- -c -yAdmin,%adminpasswd% "-O&%acrlogfile%" -s%basedir% %arcbackupdir%.bak0%DATE%-backup.ssa $/
ECHO ======ARCIVE.LOG END [%DATE%][%TIME%]======== >>%acrlogfile% ECHO =======ARCHIEVE COMPLETE=======>>%LOGFILE%
:UNLOCKVSS :: UNLOCK DATABASE if defined unlockDB del %vsslockfile%
:: EMPTY TEMP :: ---------- rd /s/q %tempdir% md %tempdir%
:: ADMIN NOTIFICATION :: ------------------ find "No errors or inconsistencies found" %localdatadir%backupanalyze.log if Errorlevel 1 ( time/t >> %logfile% ::NET send %VSSAdmin% "VSS Maint Problem. Look at %sharename%databackupanalyze.log or %LOGFILE%" ::NET send %VSSBackupAdmin% "VSS Maint Problem. Look at %sharename%databackupanalyze.log or %LOGFILE%" echo "VSS Maint Problem. Look at %sharename%databackupanalyze.log">>%logfile% if exist sendemails_on bmail -s %MailServer% -t %VSSadminEmail% -f %VSSadminEmail% -a "VSS SCRIPT" -h -m %logfile%
) else ( time/t >> %logfile% ::NET send %VSSAdmin% "VSSMaint.cmd is Sussessful. log file : %LOGFILE%" ::NET send %VSSBackupAdmin% "VSSMaint.cmd is Sussessful. log file : %LOGFILE%" if exist sendemails_on bmail -s %MailServer% -t %VSSadminEmail% -f %VSSadminEmail% -a "VSS SCRIPT" -h -m %logfile%
)
echo RE-SHARING VSS %sharename% >>%logfile% call :reShareVSS ECHO --------------- END OF LOG ENTRY -------------->>%logfile% ECHO ===============================================>>%logfile% ECHO .>>%logfile% ECHO .>>%logfile% goto :EOF
:HELP ECHO Visual SourceSafe Maintenance Script ECHO ==================================== ECHO VSSMAINT [/?] [COPY] ECHO [-copy] copy of data tree to data.bak ECHO [/?] HELP ECHO . ECHO Analyze puts its log info in databackupanalyze.log,which is also copied to ECHO a log file generated by this script %LOGFILE% ECHO For each analyze run, we preserve the existing databackup dir. ECHO At the end of three runs: ECHO databackup.0 is the original run, ECHO databackup.1 is the next run, and ECHO databackup is the most recent run. ECHO data.bak is a copy of the data dir, prior to the original run. ECHO data.bak0 is a copy of data.bak from the previous maintenance cycle.
:unShareVSS call :mkSharecmd %sharename% rmtshare %sharename% /delete goto :EOF
:reShareVSS call reshare.cmd
goto :EOF
:mkSharecmd set sharecmd=rmtshare %1 :: get the local share directory for /f "tokens=2" %%a in ('rmtshare %1^|findstr /b "Path"') do ( set sharecmd=%sharecmd%=%%a ) :: now get the current share permissions for /f "tokens=*" %%a in ('rmtshare %1^|findstr /b /c:" "') do ( for /f "tokens=1,3" %%b in ("%%a") do ( @call :exec set sharecmd=%%sharecmd%% /grant %%b:%%c ) ) echo %sharecmd%>reShare.cmd echo ------- %sharecmd%------- goto :EOF
|