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.

934 lines
34 KiB

  1. '
  2. ' Copyright (c) Microsoft Corporation. All rights reserved.
  3. '
  4. ' VBScript Source File
  5. '
  6. ' Script Name: IIsBack.vbs
  7. '
  8. Option Explicit
  9. On Error Resume Next
  10. ' Error codes
  11. Const ERR_OK = 0
  12. Const ERR_GENERAL_FAILURE = 1
  13. '''''''''''''''''''''
  14. ' Messages
  15. Const L_SwitchNeedArg_ErrorMessage = "Switch needs argument."
  16. Const L_Created_Text = "Backup %1 version %2 has been CREATED."
  17. Const L_Restored_Text = "Backup %1 version %2 has been RESTORED."
  18. Const L_Deleted_Text = "Backup %1 version %2 has been DELETED."
  19. Const L_BackupName_Text = "Backup Name"
  20. Const L_BackupVersion_Text = "Version #"
  21. Const L_DateTime_Text = "Date/Time"
  22. Const L_Error_ErrorMessage = "Error &H%1: %2"
  23. Const L_OperationRequired_ErrorMessage = "Please specify an operation before the arguments."
  24. Const L_MinInfoNeeded_ErrorMessage = "Need at least <BackupName>."
  25. Const L_NeedNameVersion_ErrorMessage = "Need at least <BackupName> and <BackupVersion>."
  26. Const L_NotEnoughParams_ErrorMessage = "Not enough parameters."
  27. Const L_OnlyOneOper_ErrorMessage = "Please specify only one operation at a time."
  28. Const L_ComputerObj_ErrorMessage = "Unable to get computer object."
  29. Const L_Backup_ErrorMessage = "Unable to backup metabase."
  30. Const L_Restore_ErrorMessage = "Unable to restore metabase."
  31. Const L_Delete_ErrorMessage = "Unable to delete metabase backup."
  32. Const L_List_ErrorMessage = "Unable to list metabase backups."
  33. Const L_NoBackups_Message = "No backups exist."
  34. Const L_ScriptHelper_ErrorMessage = "Could not create an instance of the"
  35. Const L_ScriptHelperp2_ErrorMessage = "IIsScriptHelper object."
  36. Const L_ChkScpHelperReg_ErrorMessage = "Please register the Microsoft.IIsScriptHelper"
  37. Const L_ChkScpHelperRegp2_ErrorMessage = "component."
  38. Const L_CmdLib_ErrorMessage = "Could not create an instance of the CmdLib object."
  39. Const L_ChkCmdLibReg_ErrorMessage = "Please register the Microsoft.CmdLib component."
  40. Const L_PassWithoutUser_ErrorMessage = "Please specify /u switch before using /p."
  41. Const L_WMIConnect_ErrorMessage = "Could not connect to WMI provider."
  42. Const L_BackupNotFound_ErrorMessage = "Backup doesn't exist."
  43. Const L_VersionTooBig_ErrorMessage = "Version number is too big."
  44. Const L_LastVersionTooBig_ErrorMessage = "A backup already exists with this name and the"
  45. Const L_LastVersionTooBigp2_ErrorMessage="maximum allowed version number."
  46. Const L_InvalidVersion_ErrorMessage = "Invalid version number."
  47. Const L_InvalidBackupName_ErrorMessage = "Invalid backup name."
  48. Const L_IncorrectPassword_ErrorMessage = "The password specified is incorrect."
  49. Const L_BackupExists_ErrorMessage = "Backup already exists. Please specify another name"
  50. Const L_BackupExistsp2_ErrorMessage = "or use /overwrite."
  51. Const L_InvalidSwitch_ErrorMessage = "Invalid switch: %1"
  52. Const L_Admin_ErrorMessage = "You cannot run this command because you are not an"
  53. Const L_Adminp2_ErrorMessage = "administrator on the server you are trying to configure."
  54. '''''''''''''''''''''
  55. ' Help
  56. ' General help messages
  57. Const L_SeeHelp_Message = "Type IIsBack /? for help."
  58. Const L_SeeBackupHelp_Message = "Type IIsBack /backup /? for help."
  59. Const L_SeeRestoreHelp_Message = "Type IIsBack /restore /? for help."
  60. Const L_SeeDeleteHelp_Message = "Type IIsBack /delete /? for help."
  61. Const L_SeeListHelp_Message = "Type IIsBack /list /? for help."
  62. Const L_Help_HELP_General01_Text = "Description: backup/restore IIS configuration, delete backups,"
  63. Const L_Help_HELP_General01p2_Text = " list all backups"
  64. Const L_Help_HELP_General02_Text = "Syntax: IIsBack [/s <server> [/u <username>"
  65. Const L_Help_HELP_General03_Text = " [/p <password>]]] /<operation> [arguments]"
  66. Const L_Help_HELP_General04_Text = "Parameters:"
  67. Const L_Help_HELP_General06_Text = "Value Description"
  68. Const L_Help_HELP_General07_Text = "/s <server> Connect to machine <server>"
  69. Const L_Help_HELP_General07p2_Text = " [Default: this system]"
  70. Const L_Help_HELP_General08_Text = "/u <username> Connect as <domain>\<username> or"
  71. Const L_Help_HELP_General09_Text = " <username> [Default: current user]"
  72. Const L_Help_HELP_General10_Text = "/p <password> Password for the <username> user"
  73. Const L_Help_HELP_General11_Text = "<operation> /backup Backup the IIS Server"
  74. Const L_Help_HELP_General12_Text = " (includes all site data"
  75. Const L_Help_HELP_General12p2_Text = " and settings)."
  76. Const L_Help_HELP_General13_Text = " /restore Restore the IIS Server"
  77. Const L_Help_HELP_General14_Text = " from backup (overwrites"
  78. Const L_Help_HELP_General14p2_Text = " all site data and settings)."
  79. Const L_Help_HELP_General15_Text = " /delete Deletes a backup."
  80. Const L_Help_HELP_General16_Text = " /list List all backups."
  81. Const L_Help_HELP_General17_Text = "For detailed usage:"
  82. Const L_Help_HELP_General18_Text = "IIsBack /backup /?"
  83. Const L_Help_HELP_General19_Text = "IIsBack /restore /?"
  84. Const L_Help_HELP_General20_Text = "IIsBack /delete /?"
  85. Const L_Help_HELP_General21_Text = "IIsBack /list /?"
  86. ' Common to all status change commands
  87. Const L_Help_HELP_Common17_Text = "/b <BackupName> Description for the backup file."
  88. Const L_Help_HELP_Common17p1_Text = " [Default: ""SampleBackup""]"
  89. Const L_Help_HELP_Common11_Text = "Examples:"
  90. ' Backup help messages
  91. Const L_Help_HELP_Backup01_Text = "Description: Backup the IIS Server (includes all site data"
  92. Const L_Help_HELP_Backup01p2_Text = " and settings)."
  93. Const L_Help_HELP_Backup02_Text = "Syntax: IIsBack [/s <server> [/u <username> [/p <password>]]]"
  94. Const L_Help_HELP_Backup02p1_Text = " /backup [/b <BackupName>] [/v <VersionNumber>]"
  95. Const L_Help_HELP_Backup02p2_Text = " [/e <BackupPassword>] [/overwrite]"
  96. Const L_Help_HELP_Backup18_Text = "/v <VersionNumber> Specifies the version number to be"
  97. Const L_Help_HELP_Backup18p1_Text = " assigned to the backup. Can be any"
  98. Const L_Help_HELP_Backup18p2_Text = " integer, HIGHEST_VERSION, or"
  99. Const L_Help_HELP_Backup18p3_Text = " NEXT_VERSION. [Default: NEXT_VERSION]"
  100. Const L_Help_HELP_Backup19_Text = "/e <BackupPassword> Encrypt the backup file with the"
  101. Const L_Help_HELP_Backup19p2_Text = " provided password"
  102. Const L_Help_HELP_Backup20_Text = "/overwrite Back up even if a backup of the same"
  103. Const L_Help_HELP_Backup20p1_Text = " name and version exists in the"
  104. Const L_Help_HELP_Backup20p2_Text = " specified location, overwriting if"
  105. Const L_Help_HELP_Backup20p3_Text = " necessary. [Default: disabled]"
  106. Const L_Help_HELP_Backup21_Text = "IIsBack /backup"
  107. Const L_Help_HELP_Backup22_Text = "IIsBack /s Server1 /u Administrator /p p@ssW0rd /backup /b NewBackup"
  108. ' Restore help messages
  109. Const L_Help_HELP_Restore01_Text = "Description: Restore the IIS Server from backup (overwrites"
  110. Const L_Help_HELP_Restore01p1_Text = " all site data and settings)."
  111. Const L_Help_HELP_Restore02_Text = "Syntax: IIsBack [/s <server> [/u <username> [/p <password>]]]"
  112. Const L_Help_HELP_Restore02p1_Text = " /restore /b <RestoreName> [/v <VersionNumber>]"
  113. Const L_Help_HELP_Restore02p2_Text = " [/e <BackupPassword>]"
  114. Const L_Help_HELP_Restore18_Text = "/v <VersionNumber> Specifies the version number of the"
  115. Const L_Help_HELP_Restore18p1_Text = " backup. Can be any integer or"
  116. Const L_Help_HELP_Restore18p2_Text = " HIGHEST_VERSION."
  117. Const L_Help_HELP_Restore19_Text = "/e <BackupPassword> If the backup was encrypted using a"
  118. Const L_Help_HELP_Restore19p1_Text = " user specified password, you must"
  119. Const L_Help_HELP_Restore19p2_Text = " supply the correct password to"
  120. Const L_Help_HELP_Restore19p3_Text = " restore the backup."
  121. Const L_Help_HELP_Restore21_Text = "IIsBack /restore /b MyBackup /v HIGHEST_VERSION"
  122. Const L_Help_HELP_Restore22_Text = "IIsBack /s Server1 /u Administrator /p p@ssW0rd /restore /b MyBackup /v 2"
  123. ' Delete help messages
  124. Const L_Help_HELP_Delete01_Text = "Description: Delete an existing backup file."
  125. Const L_Help_HELP_Delete02_Text = "Syntax: IIsBack [/s <server> [/u <username> [/p <password>]]]"
  126. Const L_Help_HELP_Delete02p1_Text = " /delete /b <BackupName> /v <VersionNumber>"
  127. Const L_Help_HELP_Delete18_Text = "/v <VersionNumber> Specifies the version number to"
  128. Const L_Help_HELP_Delete18p1_Text = " delete. Can be integer or"
  129. Const L_Help_HELP_Delete18p2_Text = " HIGHEST_VERSION."
  130. Const L_Help_HELP_Delete19_Text = "IIsBack /delete /b MyBackup /v HIGHEST_VERSION"
  131. Const L_Help_HELP_Delete20_Text = "IIsBack /s Server1 /u Administrator /p p@ssWOrd /delete /b MyBackup /v 2"
  132. ' List help messages
  133. Const L_Help_HELP_List01_Text = "Description: List all backup files."
  134. Const L_Help_HELP_List02_Text = "Syntax: IIsBack [/s <server> [/u <username> [/p <password>]]]"
  135. Const L_Help_HELP_List02p2_Text = " /list"
  136. Const L_Help_HELP_List18_Text = "IIsBack /list"
  137. Const L_Help_HELP_List19_Text = "IIsBack /s Server1 /u Administrator /p p@ssW0rd /list"
  138. ''''''''''''''''''''''''
  139. ' Operation codes
  140. Const OPER_BACKUP = 1
  141. Const OPER_RESTORE = 2
  142. Const OPER_DELETE = 3
  143. Const OPER_LIST = 4
  144. ' Backup/Restore contants
  145. Const BACKUP_DEFAULT_NAME = "SampleBackup"
  146. Const MD_BACKUP_HIGHEST_VERSION = &HFFFFFFFE ' Backup, Restore, Delete
  147. Const MD_BACKUP_NEXT_VERSION = &HFFFFFFFF ' Backup
  148. Const MD_BACKUP_OVERWRITE = 1 ' Backup
  149. Const MD_BACKUP_SAVE_FIRST = 2 ' Backup
  150. Const MD_BACKUP_MAX_VERSION = 9999 ' Limit
  151. Const MD_BACKUP_MAX_LEN = 100 ' Limit
  152. Const MD_BACKUP_NO_MORE_BACKUPS = &H80070103 ' EnumBackups
  153. Const INVALID_VERSION = -3
  154. '
  155. ' Main block
  156. '
  157. Dim oScriptHelper, oCmdLib
  158. Dim strServer, strUser, strPassword
  159. Dim strName, strBackPassword
  160. Dim intOperation, intResult, intVersion
  161. Dim aArgs, arg
  162. Dim bOverwrite
  163. Dim strCmdLineOptions
  164. Dim oError
  165. ' Default values
  166. strServer = "."
  167. strUser = ""
  168. strPassword = ""
  169. intOperation = 0
  170. strName = BACKUP_DEFAULT_NAME
  171. strBackPassword = ""
  172. bOverwrite = False
  173. ' Instantiate the CmdLib for output string formatting
  174. Set oCmdLib = CreateObject("Microsoft.CmdLib")
  175. If Err.Number <> 0 Then
  176. WScript.Echo L_CmdLib_ErrorMessage
  177. WScript.Echo L_ChkCmdLibReg_ErrorMessage
  178. WScript.Quit(ERR_GENERAL_FAILURE)
  179. End If
  180. Set oCmdLib.ScriptingHost = WScript.Application
  181. ' Instantiate script helper object
  182. Set oScriptHelper = CreateObject("Microsoft.IIsScriptHelper")
  183. If Err.Number <> 0 Then
  184. WScript.Echo L_ScriptHelper_ErrorMessage
  185. WScript.Echo L_ScriptHelperp2_ErrorMessage
  186. WScript.Echo L_ChkScpHelperReg_ErrorMessage
  187. WScript.Echo L_ChkScpHelperRegp2_ErrorMessage
  188. WScript.Quit(ERR_GENERAL_FAILURE)
  189. End If
  190. Set oScriptHelper.ScriptHost = WScript
  191. ' Check if we are being run with cscript.exe instead of wscript.exe
  192. oScriptHelper.CheckScriptEngine
  193. ' Minimum number of parameters must exist
  194. If WScript.Arguments.Count < 1 Then
  195. WScript.Echo L_NotEnoughParams_ErrorMessage
  196. WScript.Echo L_SeeHelp_Message
  197. WScript.Quit(ERR_GENERAL_FAILURE)
  198. End If
  199. strCmdLineOptions = "[server:s:1;user:u:1;password:p:1];[backup::0;overwrite::0];restore::0;" & _
  200. "delete::0;list::0;backupname:b:1;version:v:1;bkpasswd:e:1"
  201. Set oError = oScriptHelper.ParseCmdLineOptions(strCmdLineOptions)
  202. If Not oError Is Nothing Then
  203. If oError.ErrorCode = oScriptHelper.ERROR_NOT_ENOUGH_ARGS Then
  204. ' Not enough arguments for a specified switch
  205. WScript.Echo L_NotEnoughParams_ErrorMessage
  206. WScript.Echo L_SeeHelp_Message
  207. Else
  208. ' Invalid switch
  209. oCmdLib.vbPrintf L_InvalidSwitch_ErrorMessage, Array(oError.SwitchName)
  210. WScript.Echo L_SeeHelp_Message
  211. End If
  212. WScript.Quit(ERR_GENERAL_FAILURE)
  213. End If
  214. If oScriptHelper.GlobalHelpRequested Then
  215. DisplayHelpMessage
  216. WScript.Quit(ERR_OK)
  217. End If
  218. For Each arg In oScriptHelper.Switches
  219. Select Case arg
  220. Case "server"
  221. ' Server information
  222. strServer = oScriptHelper.GetSwitch(arg)
  223. Case "user"
  224. ' User information
  225. strUser = oScriptHelper.GetSwitch(arg)
  226. Case "password"
  227. ' Password information
  228. strPassword = oScriptHelper.GetSwitch(arg)
  229. Case "backup"
  230. If (intOperation <> 0) Then
  231. WScript.Echo L_OnlyOneOper_ErrorMessage
  232. WScript.Echo L_SeeHelp_Message
  233. WScript.Quit(ERR_GENERAL_FAILURE)
  234. End If
  235. intOperation = OPER_BACKUP
  236. If oScriptHelper.IsHelpRequested(arg) Then
  237. DisplayBackupHelpMessage
  238. WScript.Quit(ERR_OK)
  239. End If
  240. If oScriptHelper.Switches.Exists("backupname") Then
  241. strName = oScriptHelper.GetSwitch("backupname")
  242. If strName = "" Then
  243. Err.Raise &H5
  244. End If
  245. Else
  246. strName = BACKUP_DEFAULT_NAME
  247. End If
  248. If oScriptHelper.Switches.Exists("version") Then
  249. intVersion = oScriptHelper.GetSwitch("version")
  250. Else
  251. intVersion = "NEXT_VERSION"
  252. End If
  253. strBackPassword = CStr(oScriptHelper.GetSwitch("bkpasswd"))
  254. If oScriptHelper.Switches.Exists("overwrite") Then
  255. bOverwrite = True
  256. End If
  257. Case "restore"
  258. If (intOperation <> 0) Then
  259. WScript.Echo L_OnlyOneOper_ErrorMessage
  260. WScript.Echo L_SeeHelp_Message
  261. WScript.Quit(ERR_GENERAL_FAILURE)
  262. End If
  263. intOperation = OPER_RESTORE
  264. If oScriptHelper.IsHelpRequested(arg) Then
  265. DisplayRestoreHelpMessage
  266. WScript.Quit(ERR_OK)
  267. End If
  268. strName = oScriptHelper.GetSwitch("backupname")
  269. If strName = "" Then
  270. WScript.Echo L_MinInfoNeeded_ErrorMessage
  271. WScript.Echo L_SeeRestoreHelp_Message
  272. WScript.Quit(ERR_GENERAL_FAILURE)
  273. End If
  274. If oScriptHelper.Switches.Exists("version") Then
  275. intVersion = oScriptHelper.GetSwitch("version")
  276. Else
  277. intVersion = "HIGHEST_VERSION"
  278. End If
  279. strBackPassword = CStr(oScriptHelper.GetSwitch("bkpasswd"))
  280. Case "delete"
  281. If (intOperation <> 0) Then
  282. WScript.Echo L_OnlyOneOper_ErrorMessage
  283. WScript.Echo L_SeeHelp_Message
  284. WScript.Quit(ERR_GENERAL_FAILURE)
  285. End If
  286. intOperation = OPER_DELETE
  287. If oScriptHelper.IsHelpRequested(arg) Then
  288. DisplayDeleteHelpMessage
  289. WScript.Quit(ERR_OK)
  290. End If
  291. strName = oScriptHelper.GetSwitch("backupname")
  292. If strName = "" Or Not oScriptHelper.Switches.Exists("version") Then
  293. WScript.Echo L_NeedNameVersion_ErrorMessage
  294. WScript.Echo L_SeeDeleteHelp_Message
  295. WScript.Quit(ERR_GENERAL_FAILURE)
  296. End If
  297. intVersion = oScriptHelper.GetSwitch("version")
  298. Case "list"
  299. If (intOperation <> 0) Then
  300. WScript.Echo L_OnlyOneOper_ErrorMessage
  301. WScript.Echo L_SeeHelp_Message
  302. WScript.Quit(ERR_GENERAL_FAILURE)
  303. End If
  304. intOperation = OPER_LIST
  305. If oScriptHelper.IsHelpRequested(arg) Then
  306. DisplayListHelpMessage
  307. WScript.Quit(ERR_OK)
  308. End If
  309. End Select
  310. Next
  311. ' Check Parameters
  312. If intOperation = 0 Then
  313. WScript.Echo L_OperationRequired_ErrorMessage
  314. WScript.Echo L_SeeHelp_Message
  315. WScript.Quit(ERR_GENERAL_FAILURE)
  316. End If
  317. ' Validate backup name
  318. ValidateBackupName strName
  319. If Err.Number Then
  320. WScript.Echo L_InvalidBackupName_ErrorMessage
  321. WScript.Quit(Err.Number)
  322. End If
  323. ' Validate version
  324. intVersion = ValidateVersionNumber(intVersion)
  325. If Err.Number Then
  326. Select Case Err.Number
  327. Case &H6
  328. WScript.Echo L_VersionTooBig_ErrorMessage
  329. Case &H5
  330. WScript.Echo L_InvalidVersion_ErrorMessage
  331. End Select
  332. WScript.Quit(Err.Number)
  333. End If
  334. ' Check if /p is specified but /u isn't. In this case, we should bail out with an error
  335. If oScriptHelper.Switches.Exists("password") And Not oScriptHelper.Switches.Exists("user") Then
  336. WScript.Echo L_PassWithoutUser_ErrorMessage
  337. WScript.Quit(ERR_GENERAL_FAILURE)
  338. End If
  339. ' Check if /u is specified but /p isn't. In this case, we should ask for a password
  340. If oScriptHelper.Switches.Exists("user") And Not oScriptHelper.Switches.Exists("password") Then
  341. strPassword = oCmdLib.GetPassword
  342. End If
  343. ' Initializes authentication with remote machine
  344. intResult = oScriptHelper.InitAuthentication(strServer, strUser, strPassword)
  345. If intResult <> 0 Then
  346. WScript.Quit(intResult)
  347. End If
  348. ' Choose operation
  349. Select Case intOperation
  350. Case OPER_BACKUP
  351. intResult = BackupMetabase(strName, intVersion, strBackPassword, bOverwrite)
  352. Case OPER_RESTORE
  353. intResult = RestoreMetabase(strName, intVersion, strBackPassword)
  354. Case OPER_DELETE
  355. intResult = DeleteBackup(strName, intVersion)
  356. Case OPER_LIST
  357. intResult = ListBackups()
  358. End Select
  359. ' Return value to command processor
  360. WScript.Quit(intResult)
  361. '''''''''''''''''''''''''
  362. ' End Of Main Block
  363. '''''''''''''''''''''
  364. '''''''''''''''''''''''''''
  365. ' DisplayHelpMessage
  366. '''''''''''''''''''''''''''
  367. Sub DisplayHelpMessage()
  368. WScript.Echo L_Help_HELP_General01_Text
  369. WScript.Echo L_Help_HELP_General01p2_Text
  370. WScript.Echo
  371. WScript.Echo L_Help_HELP_General02_Text
  372. WScript.Echo L_Help_HELP_General03_Text
  373. WScript.Echo
  374. WScript.Echo L_Help_HELP_General04_Text
  375. WScript.Echo
  376. WScript.Echo L_Help_HELP_General06_Text
  377. WScript.Echo L_Help_HELP_General07_Text
  378. WScript.Echo L_Help_HELP_General07p2_Text
  379. WScript.Echo L_Help_HELP_General08_Text
  380. WScript.Echo L_Help_HELP_General09_Text
  381. WScript.Echo L_Help_HELP_General10_Text
  382. WScript.Echo L_Help_HELP_General11_Text
  383. WScript.Echo L_Help_HELP_General12_Text
  384. WScript.Echo L_Help_HELP_General12p2_Text
  385. WScript.Echo L_Help_HELP_General13_Text
  386. WScript.Echo L_Help_HELP_General14_Text
  387. WScript.Echo L_Help_HELP_General14p2_Text
  388. WScript.Echo L_Help_HELP_General15_Text
  389. WScript.Echo L_Help_HELP_General16_Text
  390. WScript.Echo
  391. WScript.Echo L_Help_HELP_General17_Text
  392. WScript.Echo
  393. WScript.Echo L_Help_HELP_General18_Text
  394. WScript.Echo L_Help_HELP_General19_Text
  395. WScript.Echo L_Help_HELP_General20_Text
  396. WScript.Echo L_Help_HELP_General21_Text
  397. End Sub
  398. Sub DisplayBackupHelpMessage()
  399. WScript.Echo L_Help_HELP_Backup01_Text
  400. WScript.Echo L_Help_HELP_Backup01p2_Text
  401. WScript.Echo
  402. WScript.Echo L_Help_HELP_Backup02_Text
  403. WScript.Echo L_Help_HELP_Backup02p1_Text
  404. WScript.Echo L_Help_HELP_Backup02p2_Text
  405. WScript.Echo
  406. WScript.Echo L_Help_HELP_General04_Text
  407. WScript.Echo
  408. WScript.Echo L_Help_HELP_General06_Text
  409. WScript.Echo L_Help_HELP_General07_Text
  410. WScript.Echo L_Help_HELP_General07p2_Text
  411. WScript.Echo L_Help_HELP_General08_Text
  412. WScript.Echo L_Help_HELP_General09_Text
  413. WScript.Echo L_Help_HELP_General10_Text
  414. WScript.Echo L_Help_HELP_Common17_Text
  415. WScript.Echo L_Help_HELP_Common17p1_Text
  416. WScript.Echo L_Help_HELP_Backup18_Text
  417. WScript.Echo L_Help_HELP_Backup18p1_Text
  418. WScript.Echo L_Help_HELP_Backup18p2_Text
  419. WScript.Echo L_Help_HELP_Backup18p3_Text
  420. WScript.Echo L_Help_HELP_Backup19_Text
  421. WScript.Echo L_Help_HELP_Backup19p2_Text
  422. WScript.Echo L_Help_HELP_Backup20_Text
  423. WScript.Echo L_Help_HELP_Backup20p1_Text
  424. WScript.Echo L_Help_HELP_Backup20p2_Text
  425. WScript.Echo L_Help_HELP_Backup20p3_Text
  426. WScript.Echo
  427. WScript.Echo L_Help_HELP_Common11_Text
  428. WScript.Echo
  429. WScript.Echo L_Help_HELP_Backup21_Text
  430. WScript.Echo L_Help_HELP_Backup22_Text
  431. End Sub
  432. Sub DisplayRestoreHelpMessage()
  433. WScript.Echo L_Help_HELP_Restore01_Text
  434. WScript.Echo L_Help_HELP_Restore01p1_Text
  435. WScript.Echo
  436. WScript.Echo L_Help_HELP_Restore02_Text
  437. WScript.Echo L_Help_HELP_Restore02p1_Text
  438. WScript.Echo L_Help_HELP_Restore02p2_Text
  439. WScript.Echo
  440. WScript.Echo L_Help_HELP_General04_Text
  441. WScript.Echo
  442. WScript.Echo L_Help_HELP_General06_Text
  443. WScript.Echo L_Help_HELP_General07_Text
  444. WScript.Echo L_Help_HELP_General07p2_Text
  445. WScript.Echo L_Help_HELP_General08_Text
  446. WScript.Echo L_Help_HELP_General09_Text
  447. WScript.Echo L_Help_HELP_General10_Text
  448. WScript.Echo L_Help_HELP_Common17_Text
  449. WScript.Echo L_Help_HELP_Common17p1_Text
  450. WScript.Echo L_Help_HELP_Restore18_Text
  451. WScript.Echo L_Help_HELP_Restore18p1_Text
  452. WScript.Echo L_Help_HELP_Restore18p2_Text
  453. WScript.Echo L_Help_HELP_Restore19_Text
  454. WScript.Echo L_Help_HELP_Restore19p1_Text
  455. WScript.Echo L_Help_HELP_Restore19p2_Text
  456. WScript.Echo L_Help_HELP_Restore19p3_Text
  457. WScript.Echo
  458. WScript.Echo L_Help_HELP_Common11_Text
  459. WScript.Echo
  460. WScript.Echo L_Help_HELP_Restore21_Text
  461. WScript.Echo L_Help_HELP_Restore22_Text
  462. End Sub
  463. Sub DisplayDeleteHelpMessage()
  464. WScript.Echo L_Help_HELP_Delete01_Text
  465. WScript.Echo
  466. WScript.Echo L_Help_HELP_Delete02_Text
  467. WScript.Echo L_Help_HELP_Delete02p1_Text
  468. WScript.Echo
  469. WScript.Echo L_Help_HELP_General04_Text
  470. WScript.Echo
  471. WScript.Echo L_Help_HELP_General06_Text
  472. WScript.Echo L_Help_HELP_General07_Text
  473. WScript.Echo L_Help_HELP_General07p2_Text
  474. WScript.Echo L_Help_HELP_General08_Text
  475. WScript.Echo L_Help_HELP_General09_Text
  476. WScript.Echo L_Help_HELP_General10_Text
  477. WScript.Echo L_Help_HELP_Common17_Text
  478. WScript.Echo L_Help_HELP_Common17p1_Text
  479. WScript.Echo L_Help_HELP_Delete18_Text
  480. WScript.Echo L_Help_HELP_Delete18p1_Text
  481. WScript.Echo L_Help_HELP_Delete18p2_Text
  482. WScript.Echo
  483. WScript.Echo L_Help_HELP_Common11_Text
  484. WScript.Echo
  485. WScript.Echo L_Help_HELP_Delete19_Text
  486. WScript.Echo L_Help_HELP_Delete20_Text
  487. End Sub
  488. Sub DisplayListHelpMessage()
  489. WScript.Echo L_Help_HELP_List01_Text
  490. WScript.Echo
  491. WScript.Echo L_Help_HELP_List02_Text
  492. WScript.Echo L_Help_HELP_List02p2_Text
  493. WScript.Echo
  494. WScript.Echo L_Help_HELP_General04_Text
  495. WScript.Echo
  496. WScript.Echo L_Help_HELP_General06_Text
  497. WScript.Echo L_Help_HELP_General07_Text
  498. WScript.Echo L_Help_HELP_General07p2_Text
  499. WScript.Echo L_Help_HELP_General08_Text
  500. WScript.Echo L_Help_HELP_General09_Text
  501. WScript.Echo L_Help_HELP_General10_Text
  502. WScript.Echo
  503. WScript.Echo L_Help_HELP_Common11_Text
  504. WScript.Echo
  505. WScript.Echo L_Help_HELP_List18_Text
  506. WScript.Echo L_Help_HELP_List19_Text
  507. End Sub
  508. '''''''''''''''''''''''''''
  509. ' BackupMetabase
  510. '''''''''''''''''''''''''''
  511. Function BackupMetabase(strName, intVersion, strBackPassword, bOverwrite)
  512. Dim ComputerObj
  513. Dim intFlags
  514. Dim strVersion
  515. On Error Resume Next
  516. oScriptHelper.WMIConnect
  517. If Err Then
  518. WScript.Echo L_WMIConnect_ErrorMessage
  519. oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  520. BackupMetabase = Err.Number
  521. Exit Function
  522. End If
  523. ' Grab the computer object
  524. Set ComputerObj = oScriptHelper.ProviderObj.Get("IIsComputer='LM'")
  525. If Err.Number Then
  526. Select Case Err.Number
  527. Case &H80070005
  528. WScript.Echo L_Admin_ErrorMessage
  529. WScript.Echo L_Adminp2_ErrorMessage
  530. Case Else
  531. WScript.Echo L_ComputerObj_ErrorMessage
  532. oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  533. End Select
  534. BackupMetabase = Err.Number
  535. Exit Function
  536. End If
  537. ' Build backup flags
  538. intFlags = MD_BACKUP_SAVE_FIRST
  539. If bOverwrite Then
  540. intFlags = intFlags Or MD_BACKUP_OVERWRITE
  541. End If
  542. ' Call Backup method
  543. ComputerObj.BackupWithPassword strName, intVersion, intFlags, strBackPassword
  544. If Err.Number Then
  545. Select Case Err.Number
  546. Case &H8007007B
  547. WScript.Echo L_LastVersionTooBig_ErrorMessage
  548. WScript.Echo L_LastVersionTooBigp2_ErrorMessage
  549. Case &H80070002
  550. WScript.Echo L_BackupNotFound_ErrorMessage
  551. Case &H80070050
  552. WScript.Echo L_BackupExists_ErrorMessage
  553. WScript.Echo L_BackupExistsp2_ErrorMessage
  554. Case Else
  555. WScript.Echo L_Backup_ErrorMessage
  556. WScript.Echo Err.Description
  557. End Select
  558. BackupMetabase = Err.Number
  559. Exit Function
  560. End If
  561. ' Pretty print
  562. If (intVersion = MD_BACKUP_NEXT_VERSION) Then
  563. strVersion = "NEXT_VERSION"
  564. Else
  565. If (intVersion = MD_BACKUP_HIGHEST_VERSION) Then
  566. strVersion = "HIGHEST_VERSION"
  567. Else
  568. strVersion = CStr(intVersion)
  569. End If
  570. End If
  571. oCmdLib.vbPrintf L_Created_Text, Array(strName, strVersion)
  572. ' Release object
  573. Set ComputerObj = Nothing
  574. BackupMetabase = 0
  575. End Function
  576. '''''''''''''''''''''''''''
  577. ' RestoreMetabase
  578. '''''''''''''''''''''''''''
  579. Function RestoreMetabase(strName, intVersion, strBackPassword)
  580. Dim ComputerObj
  581. Dim strVersion
  582. On Error Resume Next
  583. oScriptHelper.WMIConnect
  584. If Err Then
  585. WScript.Echo L_WMIConnect_ErrorMessage
  586. oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  587. RestoreMetabase = Err.Number
  588. Exit Function
  589. End If
  590. ' Grab the computer object
  591. Set ComputerObj = oScriptHelper.ProviderObj.Get("IIsComputer='LM'")
  592. If Err.Number Then
  593. Select Case Err.Number
  594. Case &H80070005
  595. WScript.Echo L_Admin_ErrorMessage
  596. WScript.Echo L_Adminp2_ErrorMessage
  597. Case Else
  598. WScript.Echo L_ComputerObj_ErrorMessage
  599. oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  600. End Select
  601. RestoreMetabase = Err.Number
  602. Exit Function
  603. End If
  604. ' Call Restore method
  605. ComputerObj.RestoreWithPassword strName, intVersion, 0, strBackPassword
  606. If Err.Number Then
  607. Select Case Err.Number
  608. Case &H80070057
  609. WScript.Echo L_BackupNotFound_ErrorMessage
  610. Case &H8007052B
  611. WScript.Echo L_IncorrectPassword_ErrorMessage
  612. Case Else
  613. WScript.Echo L_Restore_ErrorMessage
  614. oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  615. End Select
  616. RestoreMetabase = Err.Number
  617. Exit Function
  618. End If
  619. ' Pretty print
  620. If (intVersion = MD_BACKUP_NEXT_VERSION) Then
  621. strVersion = "NEXT_VERSION"
  622. Else
  623. If (intVersion = MD_BACKUP_HIGHEST_VERSION) Then
  624. strVersion = "HIGHEST_VERSION"
  625. Else
  626. strVersion = CStr(intVersion)
  627. End If
  628. End If
  629. oCmdLib.vbPrintf L_Restored_Text, Array(strName, strVersion)
  630. ' Release object
  631. Set ComputerObj = Nothing
  632. RestoreMetabase = 0
  633. End Function
  634. '''''''''''''''''''''''''''
  635. ' DeleteBackup
  636. '''''''''''''''''''''''''''
  637. Function DeleteBackup(strName, intVersion)
  638. Dim ComputerObj
  639. Dim strVersion
  640. On Error Resume Next
  641. oScriptHelper.WMIConnect
  642. If Err Then
  643. WScript.Echo L_WMIConnect_ErrorMessage
  644. oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  645. DeleteMetabase = Err.Number
  646. Exit Function
  647. End If
  648. ' Grab the computer object
  649. Set ComputerObj = oScriptHelper.ProviderObj.Get("IIsComputer='LM'")
  650. If Err.Number Then
  651. Select Case Err.Number
  652. Case &H80070005
  653. WScript.Echo L_Admin_ErrorMessage
  654. WScript.Echo L_Adminp2_ErrorMessage
  655. Case Else
  656. WScript.Echo L_ComputerObj_ErrorMessage
  657. oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  658. End Select
  659. DeleteBackup = Err.Number
  660. Exit Function
  661. End If
  662. ' Call Delete method
  663. ComputerObj.DeleteBackup strName, intVersion
  664. If Err Then
  665. WScript.Echo L_Delete_ErrorMessage
  666. Select Case Err.Number
  667. Case &H80070002
  668. WScript.Echo L_BackupNotFound_ErrorMessage
  669. Case &H8007052B
  670. WScript.Echo L_IncorrectPassword_ErrorMessage
  671. Case Else
  672. WScript.Echo Err.Description
  673. End Select
  674. DeleteBackup = Err.Number
  675. Exit Function
  676. End If
  677. ' Pretty print
  678. If (intVersion = MD_BACKUP_NEXT_VERSION) Then
  679. strVersion = "NEXT_VERSION"
  680. Else
  681. If (intVersion = MD_BACKUP_HIGHEST_VERSION) Then
  682. strVersion = "HIGHEST_VERSION"
  683. Else
  684. strVersion = CStr(intVersion)
  685. End If
  686. End If
  687. oCmdLib.vbPrintf L_Deleted_Text, Array(strName, strVersion)
  688. ' Release object
  689. Set ComputerObj = Nothing
  690. DeleteBackup = 0
  691. End Function
  692. '''''''''''''''''''''''''''
  693. ' ListBackups
  694. '''''''''''''''''''''''''''
  695. Function ListBackups()
  696. Dim ComputerObj
  697. Dim strName, strVersion, strDateTime, strFmtDateTime
  698. Dim dtDate, dtTime
  699. Dim intIndex
  700. Dim firstLen, verLen
  701. On Error Resume Next
  702. oScriptHelper.WMIConnect
  703. If Err.Number Then
  704. WScript.Echo L_WMIConnect_ErrorMessage
  705. oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  706. ListBackups = Err.Number
  707. Exit Function
  708. End If
  709. ' Grab the computer object
  710. Set ComputerObj = oScriptHelper.ProviderObj.Get("IIsComputer='LM'")
  711. If Err.Number Then
  712. Select Case Err.Number
  713. Case &H80070005
  714. WScript.Echo L_Admin_ErrorMessage
  715. WScript.Echo L_Adminp2_ErrorMessage
  716. Case Else
  717. WScript.Echo L_ComputerObj_ErrorMessage
  718. oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  719. End Select
  720. ListBackups = Err.Number
  721. Exit Function
  722. End If
  723. intIndex = 0
  724. Do While True
  725. ' Call EnumBackups method
  726. strName = ""
  727. computerObj.EnumBackups strName, intIndex, strVersion, strDateTime
  728. If (Err.Number <> 0) Then
  729. If (Err.Number = MD_BACKUP_NO_MORE_BACKUPS) Then
  730. Exit Do
  731. End If
  732. WScript.Echo L_List_ErrorMessage
  733. oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  734. Set computerObj = Nothing
  735. ListBackups = ERR_GENERAL_FAILURE
  736. Exit Function
  737. End If
  738. If intIndex = 0 Then
  739. WScript.Echo L_BackupName_Text & Space(35 - Len(L_BackupName_Text)) & L_BackupVersion_Text & _
  740. Space(15 - Len(L_BackupVersion_Text)) & L_DateTime_Text
  741. WScript.Echo "========================================================================"
  742. End If
  743. ' Format DateTime
  744. dtDate = DateSerial(Mid(strDateTime, 1, 4), Mid(strDateTime, 5, 2), Mid(strDateTime, 7, 2))
  745. dtTime = TimeSerial(Mid(strDateTime, 9, 2), Mid(strDateTime, 11, 2), Mid(strDateTime, 13, 2))
  746. strFmtDateTime = FormatDateTime(dtDate) & " " & FormatDateTime(dtTime, vbLongTime)
  747. verLen = 15 - Len(strVersion)
  748. firstLen = 35 - Len(strName)
  749. If (firstLen < 1) Then
  750. firstLen = 1
  751. verLen = 1
  752. End If
  753. WScript.Echo strName & Space(firstLen) & strVersion & Space(verLen) & strFmtDateTime
  754. intIndex = intIndex + 1
  755. Loop
  756. ' Print message in case we don't have any backups to list
  757. If intIndex = 0 Then
  758. WScript.Echo L_NoBackups_Message
  759. End If
  760. ' Release object
  761. Set ComputerObj = Nothing
  762. ListBackups = 0
  763. End Function
  764. ''''''''''''''''''''''''''''''''''''
  765. ' Helper Functions
  766. '''''''''''''''''''''''''''
  767. Function ValidateVersionNumber(Version)
  768. If IsNumeric(Version) Then
  769. Version = CInt(Version)
  770. If Version > MD_BACKUP_MAX_VERSION Then
  771. Err.Raise &H6
  772. End If
  773. If Version < 0 Then
  774. Err.Raise &H5
  775. End If
  776. ValidateVersionNumber = Version
  777. Else
  778. Select Case Version
  779. Case "HIGHEST_VERSION"
  780. ValidateVersionNumber = MD_BACKUP_HIGHEST_VERSION
  781. Case "NEXT_VERSION"
  782. ValidateVersionNumber = MD_BACKUP_NEXT_VERSION
  783. Case Else
  784. Err.Raise &H5
  785. End Select
  786. End If
  787. End Function
  788. Sub ValidateBackupName(strName)
  789. Dim i
  790. For i = 1 to Len(strName)
  791. If AscW(Mid(strName, i, 1)) >= 33 And AscW(Mid(strName, i, 1)) <= 47 Or _
  792. AscW(Mid(strName, i, 1)) >= 58 And AscW(Mid(strName, i, 1)) <= 64 Then
  793. Err.Raise &H5
  794. End If
  795. Next
  796. End Sub