End-to-End Analyze Script for Keeping a VSS Database Healthy
One of the most frequently asked questions about VSS is:
'I can't run Analyze on a weekly basis as recommended because inevitably,
there's at least one user who forgets to checkin their files on Friday
afternoon. Is there any way to disconnect users from a database? ' The
short answer is a qualified 'no'. VSS provides no way to forcibly
disconnect users from a database. The long answer is YES, but you have to
do it in Windows. My team uses the following PERL script which:
1) Forcibly disconnects all users from a VSS database
(net stop server /y);
2) Locks the VSS database (copy
\"$db\\data\\loggedin\\locked.lk\" \"$db\\data\\loggedin\\admin.lk\");
3)
Runs Analyze.exe
(system("\"$db\\win32\\analyze.exe\"","-b\"$db\\backup\"","-i-","-v4","-f","-c","-d","\"$db\\data\"");
As you'll see, our script does much more than that, but those
are the basics. Please feel free to post your own scripts in the comments
section of this post. As always, your comments and questions are
greatly appreciated. For an alternative to this script, see https://www3.primushost.com/~ckollars/backup.html#force.
Special thanks to Justin Russell for offering to bare his code to the
world. Justin, you're a scholar and a gentleman. Thank you.
# MaintainVSS
# Justin Russell
# Microsoft Corporation
# May
2003
# Performs various support services for a VSS database
use Getopt::Long;
# set defaults
my $db = "H:\\DB\\Anacortes";
my $bAnalyze = '';
my
$bBackup = '';
my $bShadow = '';
my $logroot = "G:\\MantainVSSLogs";
my
$help = '';
my $shadowpath = "
\\\\Fidalgo\\shadow\\Anacortes1";
my $backuppath =
"D:\\backups\\Anacortes";
GetOptions( "database=s" =>
\$db, # required (=) string path to
db
"analyze" => \$bAnalyze, # bool
flag: should we analyze the
db?
"backup" => \$bBackup,
# bool flag: should we backup the db?
"shadow" => \$bShadow,
# bool flag: should we recreate the shadow?
"log=s" =>
\$logroot, # required string path to
log
"shadowpath=s" => \$shadowpath,# where the database should be shadowed
to
"backuppath=s" => \$backuppath,# where the database should be backuped
to
"help|?" =>
\$help) # bool flag: should we display
help?
or
die "Couldn't get options. $!\n";
if
($help || !($bAnalyze || $bBackup || $bShadow))
{
print
"\nMaintainVSS.pl \nFor limited support contact Justin Russell \n\nUsage:
MaintainVSS.pl [--database=\"path\"] [--log=\"path\"] [--analyze]
[--backup[:\"path\"]] [--shadow[:\"path\"] \nAll options are optional (though if
you don't provide a command nothing will happen :) ), can be called in the short
form (e.g. \"-a\" instead of \"--analyze\"), and equal signs are
optional.\n\n";
exit;
}
my @daynum = localtime;
$logpath = "$logroot\\$daynum[7]\.log";
my $user = getlogin;
$now = scalar localtime;
open LOG, ">$logpath" or die "Couldn't open or create the log at $logpath:
$!\n";
print LOG "MaintainVSS started at $now by $user. \n\nToday we'll be
running the following commands on $db: \nAnalyze: $bAnalyze \nBackup: $bBackup
\nRecreate Shadow: $bShadow \n\n";
if ($bAnalyze)
{
$now = scalar
localtime;
print LOG "Starting Analyze routine at
$now.\n\n";
analyze();
}
if ($bBackup)
{
$now = scalar
localtime;
print LOG "Starting Backup routine at
$now.\n\n";
backup();
}
if ($bShadow)
{
$now = scalar
localtime;
print LOG "Starting Shadow routine at
$now.\n\n";
shadow();
}
$now = scalar localtime;
print LOG "\nScript compete at $now\n";
#
PAU
# use this to run the analyze routine
sub analyze
{
print
"Contacting users.\n";
system("net send /users \\Fidalgo going offline in 0 minutes for routine VSS
maintenance \(Analyze.exe\). Back in a few hours."); # inform users of
shutdown
print "Stopping file sharing.\n";
system("net stop
server /y"); # shut down file sharing
print "Locking
database.\n";
`copy \"$db\\data\\loggedin\\locked.lk\"
\"$db\\data\\loggedin\\admin.lk\"`; # lock the db
print "Deleting
temporary files.\n";
`del \"$db\\temp\\*.*\" /f /q`; # delete old temp
files
print "Saving backup.\n";
`copy \"$db\\backup\"
\"$db\\old\"`; # backup the backup
print "Setting up new
backup.\n";
`del \"$db\\backup\" /f /q`; # delete the existing
backup
print "Checking for old Analyze log.\n";
`del
\"$db\\backup\\analyze.log\" /f /q`; # delete analyze log, if any
# run
analyze with: -b backup, -i- non-interactive, -v4 verbose, -f fix errors, -c
compact db, -d delete unused files
print "Starting
Analyze.\n";
system("\"$db\\win32\\analyze.exe\"","-b\"$db\\backup\"","-i-","-v4","-f","-c","-d","\"$db\\data\"");
# note: no space after b switch
print "Unlocking
database.\n";
`del \"$db\\data\\loggedin\\admin.lck\"`; # unlock the
db
print "Moving and renaming the Analyze log.\n";
`move
\"$db\\backup\\analyze.log\"
\"$logroot\\analyze$daynum[7].log\"`;
print "Starting file
sharing.\n";
system("net start server"); # restart file
sharing
print "Staring \"Computer Browser\"\n";
system("net
start \"Computer Browser\"\n");
print "Starting \"Distributed File
System\"\n";
system("net start \"Distributed File
System\"\n");
print "Starting \"Backup Exec Remote Agent for Windows
NT\/2000\"\n";
system("net start \"Backup Exec Remote Agent for Windows
NT\/2000\"");
}
# use this to run the backup routine
sub backup
{
get($backuppath);
}
# use this to run the shadow recreation routine
sub
shadow
{
# Delete and recreate old Get path to avoid
keeping old files
`rd $shadowpath \/s \/q`; `md
$shadowpath`;
get($shadowpath);
}
sub get
{
# ensure path passed
exists
my $path = $_[0];
# -r- means don't include comments, -r means work
recursively
# -i- disables prompts
#
-gl specifies the destination of the Get, -gtu sets the timestamp to the
modified time,
# -gf- disables force_dir initialization,
-gwr replaces read-only files, -y sets the username
system
("$db\\win32\\ss.exe","get","\$\/","-R","-I-","-GL$path","-GTU","-GF-","-GWR","-Y$user")
== 0 or die "Couldn't run the VSS Get command: $!\n";
}
This posting is
provided "AS IS" with no warranties, and confers no rights. Microsoft kann
für die Richtigkeit und Vollständigkeit der Inhalte in dieser Newsgroup keine
Haftung übernehmen. Este mensaje se proporciona "como está" sin garantías
de ninguna clase, y no otorga ningún derecho.
Comments
Anonymous
September 08, 2003
Per MSDN's "best Visual Source Safe practices", you should probably run the 'ss physical' command on each repository. This will create a mapping file between every database file and real file in the projects. That way, when analyze says 'aaaaaaa' is corrupt, you know what real file might be impacted.Anonymous
October 14, 2003
In VSS some of the files get extension as .vss.tmp for example if the file name is format.asp the file name will be renamed to format.asp.vss.tmp. If I rename the file to format.asp it say that the file is alerady exits, but no file will be there with that name. Can you give me a solution for this. Wating for your responces. Ashwin.You can contact me at ashwinchandra_k@hotmail.comAnonymous
February 25, 2004
Welcome to my web wanderings :: End-to-End Analyze Script for Keeping a VSS Database HealthyAnonymous
February 27, 2004
The comment has been removedAnonymous
March 27, 2004
Thanks alot to Greif for the excellent VBScript - you'v helped me alot!
Another question to you all that might not be directly connected to the Blog's main idea but is very important as well...
Can I make an archive in VSS by a ranged date?
In example: I want to archive only the files that were last accessed/updated in the past month, is that possible???
Thanks ahead for you'r tremendouse contribution!
-- JoeyAnonymous
April 10, 2004
I think you can. ssarc.exe has the option "-v", the same as for ss.exe. "-v" option can specify a range of date.
see more in SSUSEXP.CHM, the user manual.Anonymous
March 14, 2006
I'm not expert on scripts, and know almost nothing about Source Safe, but I think the above may help me with a small problme I'm encountering.
I've consistently got users staying logged in to Source Safe, or leaving files open, through my Backup window. This causes the backup to consistently skip the SourceSafe files in use.
With tweaking, may I use the above script to disconnect users from the database so that I may back it up properly?
Thanks,
SteveAnonymous
June 28, 2006
Any one out there knows why it would take 14 hrs to run analyze on a DB with the -f (rebuild cache) and without the -f it run in 2 min?
Thanks again for all helpfull contributuion!!!!Anonymous
August 26, 2006
I am so [url=http://access.2surf.eu]lucky[/url] on having what I have! And good luck in yours [url=http://2access.2surf.eu]search[/url].
Just visit [url=http://access.122mb.com]my site[/url].Anonymous
August 26, 2006
I am so [url=http://access.2surf.eu]lucky[/url] on having what I have! And good luck in yours [url=http://2access.2surf.eu]search[/url].
Just visit [url=http://access.122mb.com]my site[/url].Anonymous
August 26, 2006
I am so [url=http://access.2surf.eu]lucky[/url] on having what I have! And good luck in yours [url=http://2access.2surf.eu]search[/url].
Just visit [url=http://access.122mb.com]my site[/url].Anonymous
August 26, 2006
I am so [url=http://access.2surf.eu]lucky[/url] on having what I have! And good luck in yours [url=http://2access.2surf.eu]search[/url].
Just visit [url=http://access.122mb.com]my site[/url].Anonymous
August 27, 2006
I am so [url=http://access.2surf.eu]lucky[/url] on having what I have! And good luck in yours [url=http://2access.2surf.eu]search[/url].
Just visit [url=http://access.122mb.com]my site[/url].Anonymous
August 27, 2006
good site
wellcome to our
http://bmw.dkblog.orgAnonymous
September 01, 2006
Thank you so much for this great post about <a href="http://eteamz.active.com/moneymanagement/files/management-project-software.html"">http://eteamz.active.com/moneymanagement/files/management-project-software.html" title="management project software">management project software</a> and [URL=http://eteamz.active.com/moneymanagement/files/management-project-software.html]management project software[/URL]Anonymous
September 05, 2006
Very interesting and good point about <a href="http://eteamz.active.com/moneymanagement/files/mortgage-payment.html"">http://eteamz.active.com/moneymanagement/files/mortgage-payment.html" title="mortgage payment">mortgage payment</a> and [URL=http://eteamz.active.com/moneymanagement/files/mortgage-payment.html]mortgage payment[/URL]Anonymous
September 07, 2006
Thanks for the great tips about <a href="http://paulsmall.bravehost.com/hair-loss.html"">http://paulsmall.bravehost.com/hair-loss.html" title="hair loss">hair loss</a> and [URL=http://paulsmall.bravehost.com/hair-loss.html]hair loss[/URL]Anonymous
September 07, 2006
Thanks for the great tips about <a href="http://paulsmall.bravehost.com/hair-loss.html"">http://paulsmall.bravehost.com/hair-loss.html" title="hair loss">hair loss</a> and [URL=http://paulsmall.bravehost.com/hair-loss.html]hair loss[/URL]Anonymous
September 07, 2006
Thanks for the great tips about <a href="http://paulsmall.bravehost.com/hair-loss.html"">http://paulsmall.bravehost.com/hair-loss.html" title="hair loss">hair loss</a> and [URL=http://paulsmall.bravehost.com/hair-loss.html]hair loss[/URL]Anonymous
September 07, 2006
Thanks for the great tips about <a href="http://paulsmall.bravehost.com/hair-loss.html"">http://paulsmall.bravehost.com/hair-loss.html" title="hair loss">hair loss</a> and [URL=http://paulsmall.bravehost.com/hair-loss.html]hair loss[/URL]Anonymous
September 15, 2006
I am so [url=http://access.2surf.eu]lucky[/url] on having what I have! And good luck in yours [url=http://2access.2surf.eu]search[/url].
Just visit [url=http://access.122mb.com]my site[/url].Anonymous
September 15, 2006
I am so [url=http://access.2surf.eu]lucky[/url] on having what I have! And good luck in yours [url=http://2access.2surf.eu]search[/url].
Just visit [url=http://access.122mb.com]my site[/url].Anonymous
September 16, 2006
[URL=http://http://replicarolexwatch.ir.pl]replica-rolex-watch[/URL]<a href="http://http://replicarolexwatch.ir.pl">replica rolex watch</a>Anonymous
September 28, 2006
After years of automating Visual SourceSafe(VSS), I am beginning to post and organize all my knowledgeAnonymous
April 17, 2007
Here is an alternative script that I am working on. This VSS maintenance script uses PowerShell.Anonymous
June 01, 2009
PingBack from http://indoorgrillsrecipes.info/story.php?id=4147Anonymous
June 07, 2009
PingBack from http://greenteafatburner.info/story.php?id=4412Anonymous
June 09, 2009
PingBack from http://weakbladder.info/story.php?id=4669Anonymous
June 11, 2009
PingBack from http://castironbakeware.info/story.php?title=korby-parnell-s-social-software-wunderkammer-end-to-end-analyzeAnonymous
June 13, 2009
PingBack from http://hairgrowthproducts.info/story.php?id=233Anonymous
June 19, 2009
PingBack from http://mydebtconsolidator.info/story.php?id=14313