Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

816 lines
24 KiB

  1. # ---------------------------------------------------------------------------
  2. # Script: snapbin.pl
  3. #
  4. # (c) 2000 Microsoft Corporation. All rights reserved.
  5. #
  6. # Purpose: Snapshot US binaries tree to INTL.
  7. #
  8. # Version: 1.00 (05/10/2000) : (bensont) Snap the binaries tree
  9. # 1.01 (05/10/2000) : (bensont) Create __BldInfo__usa__ file
  10. #---------------------------------------------------------------------
  11. # Set Package
  12. package SnapBin;
  13. # Set the script name
  14. $ENV{script_name} = 'snapbin.pl';
  15. # Set version
  16. $VERSION = '1.01';
  17. $DEBUG = 0;
  18. # Set required perl version
  19. require 5.003;
  20. # Use section
  21. use lib $ENV{ RazzleToolPath };
  22. use lib "$ENV{ RazzleToolPath }\\PostBuildScripts";
  23. use File::DosGlob qw(glob);
  24. use GetParams;
  25. use LocalEnvEx;
  26. use Logmsg;
  27. use strict;
  28. no strict 'vars';
  29. no strict 'refs';
  30. use vars qw($NETBIOS_COMMAND $BUILD_NAME_MASK $DEBUG);
  31. use vars qw($BinarySnapServer
  32. $BinarySnapServers
  33. $BuildNum
  34. $_BuildArch
  35. $_BuildType
  36. $_BuildBranch
  37. $SourceTree
  38. $_BuildTimeStamp);
  39. use HashText;
  40. use GetIniSetting;
  41. my $NETBIOS_COMMAND = "NET VIEW computer";
  42. my $BUILD_NAME_MASK = q(${BuildNum}.${_BuildArch}${_BuildType}.${_BuildBranch}.([0-9\-]+).${lang});
  43. $BUILD_NAME_MASK =~ s/(\.|[^[]\\a-z0-9_{}()]+)/\Q$1\E/ig;
  44. # my $BUILD_NAME_MASK = q(${BuildNum}.${_BuildArch}${_BuildType}.${_BuildBranch}.([0-9\-]+).[A-Z]{3});
  45. ($_BuildBranch,
  46. $SourceTree,
  47. $TargetTree,
  48. $SnapList,
  49. $machines,
  50. $BldInfo,
  51. $RoboCopyLog,
  52. $BuildNum,
  53. %SnapList,
  54. @machines,
  55. $RoboCopyCmd,
  56. $LogRoboCopy
  57. )=( $ENV{"_BuildBranch"},
  58. "\\\\ntdev\\release\\<_BuildBranch>\\usa\\<BuildNum>\\<_BuildArch><_BuildType>\\bin",
  59. "$ENV{_NTTREE}",
  60. "$ENV{RazzleToolPath}\\PostBuildScripts\\SnapList.txt",
  61. "machines.txt",
  62. "$ENV{_NTROOT}\\__BldInfo__usa__",
  63. ".Robocopy"
  64. );
  65. ($Mirror, $OtherOptions, $Incremental)=("/MIR");
  66. ($ROBOCOPY_ERROR, $ROBOCOPY_SERIOS_ERROR)=(8, 16);
  67. # Require section
  68. # &SourceTree
  69. #
  70. # net view the setver to see the available builds matching the
  71. # $BuildNum, $_BuildArch, $_BuildType, $_BuildBranch
  72. # implemented via the netBios pipe command
  73. sub SourceTree{
  74. # BinarySnapServer
  75. # suggested by MikeR
  76. local ($BinarySnapServer, $BuildNum, $_BuildArch, $_BuildType, $_BuildBranch, $lang) = @_;
  77. my $BUILD_NAME_MASK = $BUILD_NAME_MASK;
  78. my $NETBIOS_COMMAND = $NETBIOS_COMMAND;
  79. $NETBIOS_COMMAND =~ s/computer/$BinarySnapServer/;
  80. $BUILD_NAME_MASK =~ s/\$\{?(\w+)\b\}?/${$1}/egi;
  81. $DEBUG and print STDERR "netbios command: " , $NETBIOS_COMMAND, "\n";
  82. $DEBUG and print STDERR "build name mask: ", $BUILD_NAME_MASK, "\n";
  83. $DEBUG and print STDERR "available builds list:\n",
  84. grep
  85. {/$BUILD_NAME_MASK/i}
  86. qx($NETBIOS_COMMAND);
  87. [map
  88. {$_->[0]}
  89. map
  90. {[split /\s+/]}
  91. grep
  92. {/$BUILD_NAME_MASK/i}
  93. qx($NETBIOS_COMMAND)];
  94. }
  95. # &_BuildTimeStamp
  96. # filter out the time stamp part of the
  97. # build name
  98. sub _BuildTimeStamp{
  99. local ($_BuildTimeStamp, $BuildNum, $_BuildArch, $_BuildType, $_BuildBranch, $lang) = @_;
  100. my $BUILD_NAME_MASK = $BUILD_NAME_MASK;
  101. $BUILD_NAME_MASK =~ s/\$\{?(\w+)\b\}?/${$1}/egi;
  102. map
  103. {(s/$BUILD_NAME_MASK/$1/ig)}
  104. @$_BuildTimeStamp;
  105. $_BuildTimeStamp;
  106. }
  107. sub BinarySnapServer{
  108. #
  109. # 1. Clean the variables inherited from the default execution environment:
  110. # 2. Read the ini file to relate the build BinarySnapServer
  111. # BinarySnapServer label
  112. # suggested by MikeR
  113. # 3. Given the BinarySnapServer and the %_BUILD...% parameters, determine
  114. # the SourceTree and the _BuildTimeStamp.
  115. #
  116. #
  117. my $_BuildTimeStamps, $SourceTrees;
  118. local $BuildNum = shift;
  119. $SourceTree = undef;
  120. $BinarySnapServer = shift;
  121. $BinarySnapServers = [];
  122. push @$BinarySnapServers, $BinarySnapServer if $BinarySnapServer;
  123. scalar @$BinarySnapServers or
  124. $BinarySnapServers = [split /\s/,
  125. &GetIniSetting::GetSetting( "BinarySnapServers")];
  126. $DEBUG and print STDERR "Binary Snap Servers: @$BinarySnapServers\n";
  127. foreach my $BinarySnapServer (@$BinarySnapServers){
  128. my @arguments = ($BuildNum,
  129. $ENV{"_BuildArch"},
  130. $ENV{"_BuildType"},
  131. $ENV{"_BuildBranch"},
  132. $ENV{"lang"});
  133. $SourceTrees = &SourceTree($BinarySnapServer, @arguments);
  134. scalar @$SourceTrees or next;
  135. $SourceTree = "\\\\".$BinarySnapServer."\\".$SourceTrees->[0];
  136. $DEBUG and print STDERR "Source tree: " , $SourceTree, "\n";
  137. $_BuildTimeStamps=&_BuildTimeStamp($SourceTrees, @arguments);
  138. scalar @$_BuildTimeStamps or next;
  139. $_BuildTimeStamp = $_BuildTimeStamps->[0];
  140. $DEBUG and print STDERR "Build time stamp: ", $_BuildTimeStamp, "\n";
  141. # policy: pick the first available.
  142. $DEBUG or return;
  143. }
  144. $DEBUG or errmsg("unable to determine snap parameters for ".
  145. "binary Snap Servers: @$BinarySnapServers, ".
  146. "build number: $BuildNum, ".
  147. "giving up\n");
  148. $DEBUG or exit (0);
  149. # $DEBUG and print STDERR "\n", $NETBIOS_COMMAND, "\n";
  150. # $DEBUG and print STDERR "\n", $BUILD_NAME_MASK, "\n";
  151. }
  152. # Main Function
  153. sub CmdMain {
  154. # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  155. # Begin CmdMain code section
  156. # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  157. # Return when you want to exit on error
  158. unless ( &GetIniSetting::CheckIniFile ) {
  159. errmsg( "Failed to find ini file ..." );
  160. return;
  161. }
  162. $NETVIEW and &BinarySnapServer($BuildNum, $BinarySnapServer);
  163. &PrepareRoboCopyCmd || return;
  164. print "$RoboCopyCmd\n";
  165. $DEBUG or &ExecuteRoboCopy;
  166. {
  167. my @stack = ($RoboCopyCmd, $RoboCopyCmd, $SourceTree, $TargetTree);
  168. open (F, "$SnapList");
  169. my $startParse = 0;
  170. my @blist = ();
  171. my $flist = ();
  172. my @a = <F>;
  173. foreach (@a){
  174. next if /^;/;
  175. if (/^Additional *$/){
  176. print "Robocopy: found additional directories to snap\n";
  177. $startParse = 1;
  178. }
  179. $startParse=0 if ($startParse && $_ !~ /\S/);
  180. if ($startParse && /\S/){
  181. my @alist =
  182. split(" ", $_);
  183. if ($#alist>=2){
  184. #
  185. $f_ = undef;
  186. $alist[0] =~ s/(.*)\\([^\\]+)/$1/g and $f_=$2 if $alist[1]=~/F/;
  187. push @flist, $f_;
  188. push @blist, $alist[0];
  189. $DEBUG and print STDERR scalar(@blist),"\n";
  190. }
  191. }
  192. }
  193. close(F);
  194. foreach $cnt (0..$#blist){
  195. $dir = $blist[$cnt];
  196. $file = $flist[$cnt];
  197. $DEBUG and print STDERR "$dir\n";
  198. ($RoboCopyCmd, $RoboCopyLog, $SourceTree, $TargetTree) = @stack;
  199. $RoboCopyCmd =~ s/\\\\.*$//g;
  200. $RoboCopyLog =~ s|^.*(/LOG\+.*)$|$1.ADDED|g;
  201. chomp $RoboCopyLog;
  202. $SourceTree .= "\\$dir";
  203. $TargetTree .= "\\$dir";
  204. print "$SourceTree skipped\n" and next unless -d $SourceTree;
  205. $RoboCopyCmd = join(" ",$RoboCopyCmd, $SourceTree, $TargetTree, $RoboCopyLog, $file);
  206. print "$RoboCopyCmd\n";
  207. $DEBUG or &ExecuteRoboCopy;
  208. }
  209. ($RoboCopyCmd, $RoboCopyLog, $SourceTree, $TargetTree) = @stack;
  210. }
  211. $dummy = ($NETVIEW) ? &GenerateBldInfo :
  212. &CreateBldInfo($_BuildBranch);
  213. &countFiles;
  214. # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  215. # End CmdMain code section
  216. # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  217. }
  218. sub countFiles{
  219. &logmsg("DESTINATION CHECK: ". &backtick(<<COUNTING));
  220. \@echo on
  221. rem This is a comment
  222. : note that delayed variable expansion seems not to work.
  223. set WC=%RAZZLETOOLPATH%\\x86\\wc.exe
  224. for /F %. in ('dir /a-d/b/s %_NTTREE% ^|%WC%') do @(echo %. files in ^%_NTTREE^%)
  225. endlocal
  226. COUNTING
  227. 1;
  228. }
  229. # backtick
  230. # sample usage: &backtick("dir");
  231. # &backtick(<<BLOCKBOUNDARY);
  232. # ...cmd code...
  233. # BLOCKBOUNDARY
  234. # passes block of code to the cmd interpreter.
  235. # lines are concatenated
  236. # commened ones removed from the $cmd
  237. # useful when the code is already
  238. # developed and just needs to be inserted in place
  239. # has limitations.
  240. sub backtick{
  241. my ($cmd) = @_;
  242. my $res = undef;
  243. $cmd = join(" &", grep (!/^[REM|:]/i, ($cmd =~ /^(.+)/gm)));
  244. $res=qx ($cmd);
  245. $res;
  246. }
  247. # PrepareRoboCopyCmd
  248. # Purpose : Reference $SourceTree, $TargetTree and file $SnapList to create Robocopy statement
  249. #
  250. # Input : none
  251. # Output : 0 for fails, 1 for success
  252. #
  253. # Note : The Robocopy statement is stored in $RoboCopyCmd
  254. sub PrepareRoboCopyCmd {
  255. my ($Excludedirs, $Excludefiles, $exclude, $Cmd)=();
  256. -d $TargetTree or qx("md $TargetTree");
  257. HashText::Read_Text_Hash(0, $SnapList, \%snaplist) if ((defined $SnapList) && ($SnapList ne '-'));
  258. # HashText::Read_Text_Hash(1, $machines, \@machines);
  259. # If <var> defined in string, evaluate by the order: global variable, environment variable. Report error if can not evaluate
  260. $SourceTree =~ s/\<(\w+)\>/(eval "defined \$SnapBin::$1") ?
  261. eval "\$SnapBin::$1":((exists $ENV{$1})?
  262. $ENV{$1}:errmsg("Unable to eval $1 in $SourceTree; verify your params and your razzle."))/ge;
  263. $TargetTree =~ s/\<(\w+)\>/(eval "defined \$SnapBin::$1") ?
  264. eval "\$SnapBin::$1":((exists $ENV{$1})?
  265. $ENV{$1}:errmsg("Unable to eval $1 in $TargetTree; verify your params an your razzle."))/ge;
  266. # If source tree not exist
  267. if (!-e $SourceTree) {
  268. errmsg("Source Tree: $SourceTree not found.");
  269. }
  270. # Any above error should stop (Fail)
  271. if ($ENV{errors} > 0) {return 0;}
  272. # Parse the hash-hash table snaplist
  273. for $exclude (keys %snaplist) {
  274. $_ = $snaplist{$exclude}->{Type};
  275. $Excludedirs .= ($exclude=~/\\/)? "$SourceTree\\$exclude ": "$exclude " if /\bD\b/;
  276. $Excludefiles .= ($exclude=~/\\/)? "$SourceTree\\$exclude ": "$exclude " if (/\bF\b/);
  277. }
  278. $Excludefiles =
  279. join " ", map {glob($_)} split(" ", $Excludefiles)
  280. if ($Excludefiles);
  281. $DEBUG and print STDERR "Exclude files:", $Excludefiles, "\n";
  282. # Check if incremental run.
  283. &ChkBabTree($TargetTree, \%snaplist) and exit;
  284. # Create RoboCopyLogName as %logfile%.RoboCopy
  285. $RoboCopyLog = `uniqfile $ENV{logfile}\.Robocopy`;
  286. if (defined $Incremental) {
  287. $Mirror = ""; # non-Mirror
  288. $OtherOptions = "/XO"; # Exclude Older files
  289. }
  290. # Prepare the robocopy statement
  291. $Cmd = "Robocopy $Mirror /S /E $SourceTree $TargetTree $OtherOptions ";
  292. $Cmd .= "/XD $Excludedirs " if ($Excludedirs ne '');
  293. $Cmd .= "/XF $Excludefiles " if ($Excludefiles ne '');
  294. $RoboCopyCmd = $Cmd . " /LOG+:$RoboCopyLog";
  295. # Success
  296. return 1;
  297. }
  298. # Verify that the snaplist.txt file does not contradict with
  299. # the actual contents of the %_NTTREE%.
  300. # usage:
  301. # &ChkBabTree($TargetTreel, \%SnapList)
  302. sub ChkBabTree{
  303. my $parent = shift;
  304. my $snaplist = shift;
  305. my @children = grep {/\S/} split ("\n", qx ("dir /s/b/ad $parent"));
  306. $DEBUG and print STDERR "checking existing \%_NTTREE% subdirs: ",scalar (@children), "\n";
  307. return 0 unless @children;
  308. print "Robocopy: \"$parent\" is not empty, possibly incremental run\n"
  309. if scalar(@children);
  310. map {$_ =~ s/\Q$parent\E\\//} @children;
  311. my %hashchildren = map {$_=>$_} @children;
  312. $childrenkeys = \%hashchildren;
  313. map {$childrenkeys->{$_} =~ s/^.*\\//} @children;
  314. my @report = ();
  315. foreach $subdir (@children){
  316. my $lastdir = $childrenkeys->{$subdir};
  317. push @report, sprintf("%-30s%-30s",$lastdir,$subdir) # and delete ($snaplist->{$lastdir})
  318. if ($snaplist->{$lastdir}->{Type}=~/\bD\b$/) or () ;
  319. }
  320. foreach $lastdir (keys(%$snaplist)){
  321. next unless $snaplist->{$lastdir}->{Type}=~/\bD\b/ && $lastdir=~/\\/;
  322. my @subdir = grep {/\Q$lastdir\E/} @children;
  323. push @report, sprintf("%-30s%-30s",$lastdir,$subdir[0]) if scalar (@subdir);
  324. }
  325. unshift @report, "snaplist.txt %_NTTREE%\n".
  326. "-----------------------------------------------------"
  327. and print join ("\n", @report ), "\n\n"
  328. if scalar(@report);
  329. scalar(@report);
  330. 0;
  331. }
  332. # ExecuteRoboCopy
  333. # Purpose : Execute Robocopy Command ($RoboCopyCmd)
  334. #
  335. # Input : none
  336. # Output : none
  337. #
  338. # Note : The serious error or fatal error will be logged.
  339. sub ExecuteRoboCopy {
  340. my $r;
  341. logmsg("RoboCopyCmd : $RoboCopyCmd");
  342. logmsg("SOURCE : $SourceTree");
  343. logmsg("TARGET : $TargetTree");
  344. logmsg("RoboCopy LOGFILE : $RoboCopyLog");
  345. $r = system($RoboCopyCmd) / 256;
  346. # Determine the return value
  347. if ($r > $ROBOCOPY_SERIOS_ERROR) {
  348. errmsg("Serious error while running robocopy."); # Robocopy did not copy all files. This is either a usage error or an error due to insufficient access privileges on the source or destination directions.";
  349. } elsif ($r > $ROBOCOPY_ERROR) {
  350. errmsg("Robocopy was not able to copy some files or directories.");
  351. }
  352. }
  353. # ParseLogFile
  354. # Purpose : Parse the log file which from argument and store to $ENV{logfile} with fully path
  355. #
  356. # Input : templogfile
  357. # Output : none
  358. #
  359. # Note : The log file will contain all file get copied and extra files removed.
  360. sub ParseLogFile {
  361. my ($templogfile) = @_;
  362. my ($type, $file, %slots, %fails)=();
  363. local *F;
  364. # Read temp logfile
  365. open(F, $templogfile) || return;
  366. for(<F>) {
  367. next if (/^\s*\-*\s*$/);
  368. if (/^ROBOCOPY/) {(%slots,%fails)=(); next;}
  369. chomp;
  370. # If is error message, add to previous line
  371. if (!/^\s/) {
  372. if ($#{$fails{$type}} eq '-1') {
  373. errmsg($_);
  374. } else {
  375. ${$fails{$type}}[$#{$fails{$type}}] .= "\n$_";
  376. }
  377. next;
  378. }
  379. logmsg($_) if (defined $LogRoboCopy);
  380. # Parse information according the format of robocopy log
  381. if (/^\s+(?:New Dir\s+)?(\d+)\s+([\w\:\\]+)$/) {
  382. $path = $2;
  383. next;
  384. }
  385. if (/^\s+((?:New File)|(?:Newer)|(?:\*EXTRA File)|(?:Older))\s+(\d+)\s+([\w\.]+)/) {
  386. ($type, $file) = ($1, $3);
  387. ((/100\%/)||(/\*EXTRA File/))?push(@{$slots{$type}}, $path . $file):push(@{$fails{$type}}, $path . $file);
  388. }
  389. }
  390. close(F);
  391. # Separate the log to success and fail
  392. logmsg("\n\[Copy Success\]");
  393. for $type (keys %slots) {
  394. logmsg(" \[$type\]");
  395. for $file (@{$slots{$type}}) {
  396. logmsg("\t$file");
  397. }
  398. }
  399. if (scalar(%fails) ne 0) {
  400. errmsg("\n\[Copy Fails\]");
  401. for $type (keys %fails) {
  402. errmsg(" \[$type\]");
  403. for $file (@{$fails{$type}}) {
  404. errmsg("\t$file");
  405. }
  406. }
  407. }
  408. # If Robocopy log include into the logfile, remove the robocopy its logfile
  409. if (defined $LogRoboCopy) {
  410. unlink($templogfile);
  411. } else {
  412. logmsg("See Robocopy's logfile for more details: $templogfile");
  413. }
  414. }
  415. sub GenerateBldInfo{
  416. open(F, ">$BldInfo");
  417. print F "$BuildNum,$_BuildTimeStamp";
  418. close(F);
  419. ###Copy __blddate__ and __bldnum__ from US release server
  420. map {qx("echo F|xcopy /V /F /R /Y $theFile \%SDXROOT\%")}
  421. glob ("${SourceTree}\\congeal_scripts\\__bld*__");
  422. 1;
  423. }
  424. # CreateBldInfo
  425. # Purpose : Create build number and time stamps to $BldInfo
  426. #
  427. # Input : none
  428. # Output : none
  429. #
  430. # Note : The file $BldInfo contain one line: '<Build Number>,<Time Stamp>'
  431. #
  432. # 3552.x86fre.main.010914-1644.SRV
  433. sub CreateBldInfo {
  434. local *F;
  435. my $_BuildBranch = shift || $ENV{"_BuildBranch"} ;
  436. my @file;
  437. if ($ENV{errors} > 0) {return 0;}
  438. # Search the matched filename in $SourceTree's parent folder
  439. @file = grep {/${BuildNum}\.\w+\.$_BuildBranch\.[0-9\-]+\.[A-Z]{3}/i}
  440. glob("${SourceTree}\\..\\${BuildNum}.*.???");
  441. $DEBUG and print STDERR "\n","CreateBldInfo ${BuildNum} :\n", join("\t", @file), "\n";
  442. if (defined $file[1]) {
  443. errmsg("Non unique US marker file found.".
  444. "\n Pick the first from the list:\n" .
  445. join("\n", @file)."\n\n");
  446. } elsif (!defined $file[0]) {
  447. errmsg("Marker file not found. Please make sure the US path is valid:\n".
  448. "${SourceTree}\\..\\${BuildNum}.*.???");
  449. }
  450. if ($file[0]!~/$BuildNum\.\w+\.\w+\.([\d|\-]+).[A-Z]{3}/i) {
  451. errmsg("Marker Filename (".$file[0].") is incorrect format! Expected:\n".
  452. "$BuildNum.$_BuildArch$_BuildType.$_BuildBranch.\$_BuildTimeStamp.???");
  453. } else {
  454. open(F, ">$BldInfo");
  455. print F "$BuildNum,$1";
  456. close(F);
  457. }
  458. ###Copy __blddate__ and __bldnum__ from US release server
  459. @file=glob("${SourceTree}\\congeal_scripts\\__bld*__");
  460. for my $theFile ( @file )
  461. {
  462. system( "echo F|xcopy /V /F /R /Y $theFile $ENV{sdxroot}" );
  463. }
  464. }
  465. sub ValidateParams {
  466. #<Add your code for validating the parameters here>
  467. exists $ENV{RazzleToolPath} or
  468. errmsg("Please run under razzle or RazzleToolPath undefined") ;
  469. $BuildNum !~ /[^\d\.]/ or
  470. errmsg("Build Number ($BuildNum) contains non-digital or dot character");
  471. }
  472. sub Usage {
  473. print <<USAGE;
  474. $0 - Snap Tree from US to INTL
  475. ============================================================================
  476. Usage: $0 -n buildnum [-s SourceTree] [-t TargetTree] [-f SnapList]
  477. [-y BuildBranch] [-B bldinfo] [-L] [-i] [-d]
  478. -n Build Number : The Build Number you snapshot
  479. -s Source Tree : Source Tree
  480. -t Target Tree : Target Tree
  481. -f SnapList : A snaplist file contain which files or dirs excluded
  482. -y BuildBrahcn : Branch to snap the build from. Default %_BuildBranch%
  483. -B bldinfo : A bldinfo file should be create after snapshot
  484. -L : Include robocopy log into logfile
  485. -i : Incremental
  486. -d : Debug. Display the robocopy command without running it. Useful
  487. when you encountered the error and willing debug it.
  488. -N : use NET access to release server(s) to determine the snap location.
  489. Default behavior is rely on DFS.
  490. -B : specify the release server to form the snap location. Only used when -N
  491. flag set
  492. -? Displays usage
  493. Example:
  494. 1. Snapshot US 2121
  495. $0 -n 2121
  496. 2. Snapshot US 2222 with userlst.txt incrementally
  497. $0 -n 2222 -f userlst.txt -i
  498. 3. Snapshot US 2233 from d:\\nt8.binaries.x86fre to f:\\nt9.binaries.x86fre
  499. with userlst.txt and store buildnumber and time stamp to mynote.txt.
  500. $0 -n 2233 -s d:\\nt8.binaries.x86fre -t f:\\nt9.binaries.x86fre -f userlst.txt -B mynote.txt
  501. 4. Dummy snap the idx02 build in the Razzle enlisted in main branch.
  502. $0 -n 3505 -b idx02 -d
  503. USAGE
  504. }
  505. sub GetParams {
  506. # Step 1: Call pm getparams with specified arguments
  507. &GetParams::getparams(@_);
  508. # Step 2: Set the language into the enviroment
  509. $ENV{lang}=$lang;
  510. # Step 3: Call the usage if specified by /?
  511. if ($HELP) {
  512. &Usage();
  513. exit 1;
  514. }
  515. }
  516. sub LocalEnvEx {
  517. my ($Option)=(@_);
  518. if ($Option=~/^initalize$/i) {
  519. my $LocalEnvEx=LocalEnvEx->new;
  520. &{$LocalEnvEx->{-Initialize}};
  521. }
  522. if ($Option=~/^end$/i) {
  523. my $LocalEnvEx=LocalEnvEx->new;
  524. &{$LocalEnvEx->{-End}};
  525. }
  526. }
  527. # cmd entry point for script.
  528. if (eval("\$0 =~ /" . __PACKAGE__ . "\\.pl\$/i")) {
  529. @syntax=(
  530. '-n' => 'n:',
  531. '-o' => 's:t:y:f:LidNB:',
  532. '-p' => 'BuildNum SourceTree TargetTree _BuildBranch SnapList LogRoboCopy Incremental DEBUG NETVIEW BinarySnapServer'
  533. );
  534. # Step 1: Parse the command line
  535. &GetParams (@syntax, @ARGV);
  536. # Include local environment extensions
  537. &LocalEnvEx('initalize');
  538. # Validate the option given as parameter.
  539. &ValidateParams;
  540. # Step 4: Call the CmdMain function
  541. &CmdMain();
  542. # End local environment extensions.
  543. &LocalEnvEx('end');
  544. }
  545. # -------------------------------------------------------------------------------------------
  546. # Script: snapbin.pl
  547. # Purpose: Snapshot US binaries tree to INTL.
  548. # SD Location: %sdxroot%\tools\postbuildscripts
  549. #
  550. # (1) Code section description:
  551. # CmdMain - Prepare the robocopyCmd, execute and parse its log
  552. # PrepareRoboCopyCmd - Prepare the Robocopy command
  553. # ExecuteRoboCopy - Execute the Robocopy command and test the return value
  554. # ParseLogFile - Parse the logfile, append logfile from temp logfile
  555. #
  556. # (2) Reserved Variables -
  557. # $ENV{HELP} - Flag that specifies usage.
  558. # $ENV{lang} - The specified language. Defaults to USA.
  559. # $ENV{logfile} - The path and filename of the logs file.
  560. # $ENV{logfile_bak} - The path and filename of the logfile.
  561. # $ENV{errfile} - The path and filename of the error file.
  562. # $ENV{tmpfile} - The path and filename of the temp file.
  563. # $ENV{errors} - The scripts errorlevel.
  564. # $ENV{script_name} - The script name.
  565. # $ENV{_NTPostBld} - Abstracts the language from the files path that
  566. # postbuild operates on.
  567. #
  568. # (3) Reserved Subs -
  569. # Usage - Use this sub to discribe the scripts usage.
  570. # ValidateParams - Use this sub to verify the parameters passed to the script.
  571. #
  572. # (4) Call other executables or command scripts by using:
  573. # system "foo.exe";
  574. # Note that the executable/script you're calling with system must return a
  575. # non-zero value on errors to make the error checking mechanism work.
  576. #
  577. # Example
  578. # if (system("perl.exe foo.pl -l $lang")){
  579. # errmsg("perl.exe foo.pl -l $lang failed.");
  580. # # If you need to terminate function's execution on this error
  581. # goto End;
  582. # }
  583. #
  584. # (5) Log non-error information by using:
  585. # logmsg "<log message>";
  586. # and log error information by using:
  587. # errmsg "<error message>";
  588. #
  589. # (6) Have your changes reviewed by a member of the US build team (ntbusa) and
  590. # by a member of the international build team (ntbintl).
  591. #
  592. # -------------------------------------------------------------------------------------------
  593. =head1 NAME
  594. B<SnapBin> - Snapshot US Binaries tree to INTL
  595. =head1 SYNOPSIS
  596. &SnapBin::PrepareRoboCopyCmd;
  597. &SnapBin::ExecuteRoboCopy;
  598. &SnapBin::ParseLogFile;
  599. &SnapBin::CreateBldInfo;
  600. =head1 DESCRIPTION
  601. According SnapList,
  602. PrepareRoboCopyCmd will prepare the command, such as:
  603. Robocopy /MIR /S /E $SourceTree $TargetTree /XD xxxx /XF xxxx /LOG+:$ENV{logfile}.temp
  604. ExecuteRoboCopy execute the command and verify its log.
  605. And, ParseLogFile will append temp logfile to $ENV{logfile} and generate a separate list into log.
  606. Final, create BldInfo file in nt root.
  607. =head1 INSTANCES
  608. =head2 $SourceTree
  609. US Tree, default is \\\\ntdev\\release\\<_BuildBranch>\\usa\\<BuildNum>\\<_BuildArch><_BuildType>\\bin
  610. =head2 $TargetTree
  611. INTL Tree, default is _NTTREE
  612. =head2 $SnapList
  613. Snap List FileName, default is SnapList.txt
  614. =head2 $BuildNum
  615. Build Number, necessary defined. No default value
  616. =head2 %SnapList
  617. The hash stored by HashText::Read_Text_Hash from file $SnapList.
  618. =head2 $RoboCopyCmd
  619. The command for ExecuteRoboCopy execute
  620. =head1 METHODS
  621. =head2 PrepareRoboCopyCmd
  622. $SnapBin::SourceTree = "f:\\foo";
  623. $SnapBin::TargetTree = "f:\\bar";
  624. $SnapBin::SnapList = "mylist.txt"; # equal to '-' if no exclude list file
  625. &SnapBin::PrepareRoboCopyCmd;
  626. system("$SnapBin::RoboCopyCmd");
  627. =head2 ExecuteRoboCopy
  628. $SnapBin::SourceTree = "f:\\foo";
  629. $SnapBin::TargetTree = "f:\\bar";
  630. $SnapBin::RoboCopyCmd = "Robocopy /S $SnapBin::SourceTree $SnapBin::TargetTree";
  631. &SnapBin::ExecuteRoboCopy;
  632. =head2 ParseLogFile
  633. system("robocopy f:\\temp F:\\tempbak /LOG:abc.log");
  634. &SnapBin::ParseLogFile("abc.log");
  635. =head1 SEE ALSO
  636. HashText.pm
  637. =head1 AUTHOR
  638. Benson Tan <[email protected]>
  639. Serguei Kouzmine <[email protected]>
  640. =cut
  641. 1;