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.

448 lines
15 KiB

  1. ////////////////////////////////////////////////////////////////////////////
  2. //
  3. // This script will install/deploy the UDDI 1.5 Database structure
  4. //
  5. // Author: lucasm
  6. //
  7. ////////////////////////////////////////////////////////////////////////////
  8. ////////////////////////////////////////////////////////////////////////////
  9. // Consts
  10. //
  11. var c_logfile = "uddi.v2.builddb.log";
  12. var c_log = true;//true = log all the time
  13. var c_verbose = false;//true = output all info to console
  14. var c_dbserver = "(local)";//sql server where you want to deploy
  15. var c_dbname = "uddi_v2";//name of the uddi database
  16. var c_mode = 0;//0=DROPDB;1=CODEONLY;2=NODROP
  17. var c_datadir = "C:\\sqldata";//dir local to db server for data files
  18. var c_logdir = "C:\\sqldata";//dir local to db server for log files
  19. var c_backupdir = "C:\\sqldata";//dir local to db server for backup files
  20. var c_stagedir = "C:\\sqldata";//dir local to db server for staging files
  21. var c_scriptdir = "C:\\dev\\nt\\inetsrv\\uddi\\source\\setup\\db\\ca";//dir local to this script where the t-sql files can be found
  22. var c_backupscr = "createBackupSched.vbs";//script to run to configure backup on the db
  23. //
  24. ////////////////////////////////////////////////////////////////////////////
  25. ////////////////////////////////////////////////////////////////////////////
  26. // Globals
  27. //
  28. var g_fso = new ActiveXObject( "Scripting.FileSystemObject" );
  29. var g_shell = new ActiveXObject( "WScript.Shell" );
  30. var g_sqlserver;// = new ActiveXObject( "SQLDMO.SQLServer" );
  31. var g_logfile ;//= c_dbname + "_log.ldf";//database log file name
  32. var g_sysfile ;//= c_dbname + "_sys.mdf";//sys database file name
  33. var g_datafile1 ;//= c_dbname + "_data_1.ndf";//database data file name
  34. var g_datafile2 ;//= c_dbname + "_data_2.ndf";//database data file name
  35. var g_journfile ;//= c_dbname + "_journal_1.ndf";//database journal file name
  36. var g_stagefile ;//= c_dbname + "_stage_1.ndf";//database stageing file name
  37. //
  38. ////////////////////////////////////////////////////////////////////////////
  39. ////////////////////////////////////////////////////////////////////////////
  40. // Arrays
  41. //
  42. var g_dropdbcmd;//holds t-sql commands to drop the db
  43. var g_cleanupcmd;//holds t-sql commands to run to clean and prep filesystem
  44. var g_createdbcmd;//holds t-sql commands to create the db
  45. var g_configdbcmd;//holds t-sql commands to config the db
  46. var g_scriptarr;//holds sql file names to run to create and configure table schema
  47. var g_codescrarr;//holds sql file names that pertain to code( sprocs,funcs, etc)
  48. var g_taxonarr;//holds txt file names for taxonomy import
  49. //
  50. ////////////////////////////////////////////////////////////////////////////
  51. ////////////////////////////////////////////////////////////////////////////
  52. // This is the help screen
  53. //
  54. var c_help = " deploydb.js help \r\n"+
  55. "\r\n"+
  56. " CScript deploydb.js [(-c)odeonly|(-d)ropdb|(-n)odrop] [options]\r\n"+
  57. "\r\n"+
  58. " -c Codeonly build of the database(1)\r\n"+
  59. " -d Drop Current Database and Restart Clean(0)\r\n"+
  60. " -n Do Not Drop the Current Database(2)\r\n"+
  61. " ( Default is " + c_mode + " )\r\n" +
  62. "\r\n"+
  63. "Options:\r\n"+
  64. "\r\n"+
  65. " -s servername Name of database server( "+ c_dbserver +" )\r\n"+
  66. " -a datbase name Name of database( "+ c_dbname +" )\r\n"+
  67. " -l logname Enable logging and specify log( " + c_log + ", "+c_logfile+" )\r\n"+
  68. " -v Verbose Mode( " + c_verbose + ")\r\n"+
  69. " -D DataDir Database Data Directory( " + c_datadir + " )\r\n"+
  70. " NOTE: This path is local to the database server\r\n"+
  71. " -L LogDir Database Log Directory( " + c_logdir + " )\r\n"+
  72. " NOTE: This path is local to the database server\r\n"+
  73. " -B BackupDir Database Backup Directory( " + c_backupdir + " )\r\n"+
  74. " NOTE: This path is local to the database server\r\n"+
  75. " -S ScriptDir Database Script Location( " + c_scriptdir + " )\r\n"+
  76. " -N StagingDir Location to place Staging Files( " + c_stagedir + " )\r\n"+
  77. " -b BackupScript Script to run to install Backup Schedule\r\n" +
  78. " ( " + c_backupscr + " )\r\n"+
  79. " \r\n"+
  80. "\r\n";
  81. //
  82. ////////////////////////////////////////////////////////////////////////////
  83. ////////////////////////////////////////////////////////////////////////////
  84. // Handles command line arguments
  85. //
  86. function args( )
  87. {
  88. var i =0;
  89. try
  90. {
  91. if( WScript.Arguments.Length>0 )
  92. {
  93. if( WScript.Arguments( 0 ) =="-?"||WScript.Arguments( 0 ) =="/?" )
  94. log( c_help,6,"HELP" );
  95. for( i=0;i<WScript.Arguments.Length;i++ )
  96. {
  97. switch( WScript.Arguments( i ).substring( 0,2 ) )
  98. {
  99. case "-c":
  100. case "/c":
  101. c_mode = 1;
  102. break;
  103. case "-d":
  104. case "/d":
  105. c_mode = 0;
  106. break;
  107. case "-n":
  108. case "/n":
  109. c_mode = 2;
  110. break;
  111. case "-s":
  112. case "/s":
  113. i++;
  114. c_dbserver = WScript.Arguments( i );
  115. break;
  116. case "-a":
  117. case "/a":
  118. i++;
  119. c_dbname = WScript.Arguments( i );
  120. break;
  121. case "-l":
  122. case "/l":
  123. i++;
  124. c_log = true;
  125. c_logfile = WScript.Arguments( i );
  126. break;
  127. case "-v":
  128. case "/v":
  129. c_verbose = true;
  130. break;
  131. case "-D":
  132. case "/D":
  133. i++;
  134. c_datadir = WScript.Arguments( i );
  135. break;
  136. case "-L":
  137. case "/L":
  138. i++;
  139. c_logdir = WScript.Arguments( i );
  140. break;
  141. case "-B":
  142. case "/B":
  143. i++;
  144. c_backupdir = WScript.Arguments( i );
  145. break;
  146. case "-S":
  147. case "/S":
  148. i++;
  149. c_scriptdir = WScript.Arguments( i );
  150. break;
  151. case "-N":
  152. case "/N":
  153. i++;
  154. c_stagedir = WScript.Arguments( i );
  155. break;
  156. case "-b":
  157. case "/b":
  158. i++;
  159. c_backupscr = WScript.Arguments( i );
  160. break;
  161. default:
  162. log( "Unknown Argument near: "+ WScript.Arguments( i ) ,6,"args()" );
  163. break;
  164. }
  165. }
  166. }
  167. }
  168. catch( e )
  169. {
  170. log( "Missing Argument " ,6,"args()" );
  171. }
  172. }
  173. //
  174. ////////////////////////////////////////////////////////////////////////////
  175. ////////////////////////////////////////////////////////////////////////////
  176. // initialize all globals
  177. //
  178. function init( )
  179. {
  180. args( );
  181. if( g_fso.FileExists( c_logfile ) )
  182. g_fso.DeleteFile( c_logfile, true ) ;
  183. g_logfile = c_dbname + "_log.ldf";
  184. g_sysfile = c_dbname + "_sys.mdf";
  185. g_datafile1 = c_dbname + "_data_1.ndf";
  186. g_datafile2 = c_dbname + "_data_2.ndf";
  187. g_journfile = c_dbname + "_journal_1.ndf";
  188. g_stagefile = c_dbname + "_staging_1.ndf";
  189. g_dropdbcmd = new Array( "IF EXISTS( SELECT * FROM master..sysdatabases WHERE name='" + c_dbname + "') ALTER DATABASE " + c_dbname + " SET OFFLINE WITH ROLLBACK IMMEDIATE",
  190. "IF EXISTS( SELECT * FROM master..sysdatabases WHERE name='" + c_dbname + "') DROP DATABASE " + c_dbname);
  191. g_cleanupcmd = new Array ( "EXEC master..xp_cmdshell 'IF NOT EXIST " + c_datadir + " ( MD " + c_datadir + " )'",
  192. "EXEC master..xp_cmdshell 'IF NOT EXIST " + c_logdir + " ( MD " + c_logdir + " )'",
  193. "EXEC master..xp_cmdshell 'IF NOT EXIST " + c_backupdir + " ( MD " + c_backupdir + " )'",
  194. "EXEC master..xp_cmdshell 'IF EXIST " + checkDir( c_datadir ) + g_datafile1 + " (DEL " + checkDir( c_datadir ) + g_datafile1 + ")'",
  195. "EXEC master..xp_cmdshell 'IF EXIST " + checkDir( c_datadir ) + g_datafile2 + " (DEL " + checkDir( c_datadir ) + g_datafile2 + ")'",
  196. "EXEC master..xp_cmdshell 'IF EXIST " + checkDir( c_datadir ) + g_sysfile + " (DEL " + checkDir( c_datadir ) + g_sysfile + ")'",
  197. "EXEC master..xp_cmdshell 'IF EXIST " + checkDir( c_logdir ) + g_logfile + " (DEL " + checkDir( c_logdir ) + g_logfile + ")'",
  198. "EXEC master..xp_cmdshell 'IF EXIST " +checkDir( c_logdir ) + g_journfile + " (DEL " +checkDir( c_logdir ) + g_journfile + ")'",
  199. "EXEC master..xp_cmdshell 'IF EXIST " +checkDir( c_stagedir ) + g_stagefile + " (DEL " +checkDir( c_logdir ) + g_stagefile + ")'");
  200. g_createdbcmd = new Array( "CREATE DATABASE [" + c_dbname + "] ON PRIMARY (NAME = 'UDDI_SYS_OBJECTS', FILENAME = '" + checkDir( c_datadir) + g_sysfile + "', SIZE = 3MB, MAXSIZE = UNLIMITED, FILEGROWTH = 1MB), FILEGROUP [UDDI_CORE] (NAME = 'UDDI_CORE_1', FILENAME = '" + checkDir( c_datadir) + g_datafile1 + "', SIZE = 10MB, MAXSIZE = UNLIMITED, FILEGROWTH = 5MB), (NAME = 'UDDI_CORE_2', FILENAME = '"+checkDir( c_datadir) + g_datafile2 + "', SIZE = 10MB, MAXSIZE = UNLIMITED, FILEGROWTH = 5MB), FILEGROUP [UDDI_JOURNAL] (NAME = 'UDDI_JOURNAL_1', FILENAME = '" + checkDir( c_logdir ) + g_journfile + "', SIZE = 5MB, MAXSIZE = UNLIMITED, FILEGROWTH = 5MB), FILEGROUP [UDDI_STAGING] (NAME = 'UDDI_STAGING_1', FILENAME = '" + checkDir( c_stagedir ) + g_stagefile + "', SIZE = 5MB, MAXSIZE = UNLIMITED, FILEGROWTH = 5MB) LOG ON (NAME = 'UDDI_LOG', FILENAME = '"+checkDir( c_logdir ) + g_logfile + "', SIZE= 20MB, MAXSIZE = UNLIMITED, FILEGROWTH = 5MB)");
  201. g_configdbcmd = new Array( "EXEC master..sp_configure 'user options',16686",
  202. "RECONFIGURE",
  203. "EXEC master..sp_dboption '" + c_dbname + "','select into/bulkcopy','true'");
  204. g_scriptarr = new Array( "uddi.v2.messages.sql",
  205. "uddi.v2.ddl.sql",
  206. "uddi.v2.tableopts.sql",
  207. "uddi.v2.ri.sql",
  208. "uddi.v2.trig.sql",
  209. "uddi.v2.dml.sql");
  210. g_codescrarr = new Array( "uddi.v2.func.sql",
  211. "uddi.v2.sp.sql",
  212. "uddi.v2.uisp.sql",
  213. "uddi.v2.tModel.sql",
  214. "uddi.v2.businessEntity.sql",
  215. "uddi.v2.businessService.sql",
  216. "uddi.v2.bindingTemplate.sql",
  217. "uddi.v2.publisher.sql",
  218. "uddi.v2.repl.sql",
  219. "uddi.v2.admin.sql",
  220. "uddi.v2.sec.sql");
  221. try
  222. {
  223. g_sqlserver = new ActiveXObject( "SQLDMO.SqlServer" );
  224. log( "connecting to server: " + c_dbserver ,3,"init" );
  225. g_sqlserver.LoginSecure = true;
  226. g_sqlserver.Connect( c_dbserver );
  227. }
  228. catch( e )
  229. {
  230. if( e.message == "Automation server can't create object" )
  231. log( "SQLDMO Not Installed", 6, "SQLDMO" );
  232. else
  233. log( e.message, 6, "SQLDMO" );
  234. }
  235. }
  236. //
  237. ////////////////////////////////////////////////////////////////////////////
  238. Main();
  239. ////////////////////////////////////////////////////////////////////////////
  240. //
  241. //
  242. function Main( )
  243. {
  244. init( );
  245. if( c_mode==0 )//If DROPDB then Drop the Database
  246. {
  247. log( "Running Drop Scripts",3,"Main" );
  248. for( i=0;i<g_dropdbcmd.length;i++ )
  249. {
  250. runscript( g_dropdbcmd[ i ], "master" );
  251. }
  252. }
  253. if( c_mode!=1 )//if not CODEONLY run create database and config
  254. {
  255. for( b=0;b<g_cleanupcmd.length;b++ )
  256. {
  257. runscript( g_cleanupcmd[ b ], "master" );
  258. }
  259. WScript.Sleep( 10000 );
  260. log( "Running Create Scripts",3,"Main" );
  261. for( j=0;j<g_createdbcmd.length;j++ )
  262. {
  263. runscript( g_createdbcmd[ j ], "master" );
  264. }
  265. g_sqlserver.Databases.Refresh();
  266. for( k=0;k<g_configdbcmd.length;k++ )
  267. {
  268. runscript( g_configdbcmd[ k ], c_dbname );
  269. }
  270. for( l=0;l<g_scriptarr.length;l++ )
  271. {
  272. runscript( loadscript( checkDir( c_scriptdir ) + g_scriptarr[ l ] ), c_dbname );
  273. }
  274. }
  275. log( "Running Code Scripts",3,"Main" );
  276. for( h=0;h<g_codescrarr.length;h++ )
  277. {
  278. runscript( loadscript( checkDir( c_scriptdir ) + g_codescrarr[ h ] ), c_dbname );
  279. }
  280. log( "Running Backup Config Script( "+checkDir( c_scriptdir )+ c_backupscr+" )",3,"Main" );
  281. var scrcmd = "CSCRIPT " + checkDir( c_scriptdir ) + c_backupscr + " \"" + c_dbserver + "\" \"" + c_dbname + "\" \"" + c_backupdir + "\" ";
  282. runshell( scrcmd );
  283. }
  284. //
  285. ////////////////////////////////////////////////////////////////////////////
  286. ////////////////////////////////////////////////////////////////////////////
  287. //
  288. //
  289. function loadscript( file )
  290. {
  291. try
  292. {
  293. log( "Opening File: " + file, 2,"loadscript" );
  294. var ts = g_fso.OpenTextFile( file );
  295. var s = ts.ReadAll();
  296. ts.Close();
  297. return s;
  298. }
  299. catch( e )
  300. {
  301. log( e.description, 6, "loadscript" );
  302. }
  303. }
  304. //
  305. ////////////////////////////////////////////////////////////////////////////
  306. ////////////////////////////////////////////////////////////////////////////
  307. //
  308. //
  309. function runscript( sql, dbname )
  310. {
  311. try
  312. {
  313. var database = g_sqlserver.Databases.Item( dbname );
  314. log( sql + "\r\n",2,"runscript" );
  315. database.ExecuteImmediate( sql);
  316. database = null;
  317. }
  318. catch( e )
  319. {
  320. log( "Error occurred while running sql script: " + e.description , 6,"SQLDMO" );
  321. }
  322. }
  323. //
  324. ////////////////////////////////////////////////////////////////////////////
  325. ////////////////////////////////////////////////////////////////////////////
  326. //
  327. //
  328. function runshell( cmd )
  329. {
  330. log( "Running : " + cmd ,2,"runshell" );
  331. g_shell.Run( cmd ,true)
  332. }
  333. //
  334. ////////////////////////////////////////////////////////////////////////////
  335. ////////////////////////////////////////////////////////////////////////////
  336. //
  337. //
  338. function checkDir( string )
  339. {
  340. var newstr = g_fso.GetAbsolutePathName( string );
  341. var lstchr = newstr.substr( newstr.length-1)
  342. if( lstchr != "\\" )
  343. return newstr + "\\";
  344. else
  345. return newstr;
  346. }
  347. //
  348. ////////////////////////////////////////////////////////////////////////////
  349. ////////////////////////////////////////////////////////////////////////////
  350. //
  351. //
  352. function log( txt, lvl, lcn )
  353. {
  354. var entry = "";
  355. var date = new Date();
  356. entry += "\r\n=====================================================\r\n"+
  357. date.toString() + "\r\n" +
  358. "=====================================================\r\n"+
  359. txt + "\r\n" +
  360. "\r\n";
  361. entry += lcn + "\r\n" ;
  362. if( c_log && lcn!="HELP" )
  363. {
  364. var file = g_fso.OpenTextFile( c_logfile,8,true );
  365. file.Write( entry );
  366. file.Close();
  367. file = null;
  368. }
  369. if( c_verbose || lvl > 2 )
  370. WScript.Echo( entry );
  371. if( lvl > 5 )
  372. WScript.Quit(1);
  373. }
  374. //
  375. ////////////////////////////////////////////////////////////////////////////
  376. ////////////////////////////////////////////////////////////////////////////
  377. //
  378. //
  379. g_fso = null;
  380. g_sqlserver.Close();
  381. g_sqlserver= null;
  382. g_shell=null;
  383. //
  384. ////////////////////////////////////////////////////////////////////////////