Source code of Windows XP (NT5)
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.

112 lines
2.9 KiB

  1. '''''''''''''''''''''''''''''''''''''''''''''
  2. '
  3. ' Metabase Backup Restore Utility
  4. '
  5. '''''''''''''''''''''''''''''''''''''''''''''
  6. ' Description:
  7. ' ------------
  8. ' This sample admin script allows you to restore backups of your Metabase.
  9. '
  10. ' To Run:
  11. ' -------
  12. ' This is the format for this script:
  13. '
  14. ' cscript metabackrest.vbs
  15. '
  16. ' NOTE: If you want to execute this script directly from Windows, use
  17. ' 'wscript' instead of 'cscript'.
  18. '
  19. '''''''''''''''''''''''''''''''''''''''''''''
  20. ' Initialize error checking
  21. On Error Resume Next
  22. ' Initialize variables
  23. Dim ArgCount, BuName, BuVersion, BuFlags, CompObj, VersionMsg
  24. ' Default values
  25. ArgCount = 0
  26. BuName= "SampleBackup"
  27. BuVersion = &HFFFFFFFE ' Use highest version number
  28. BuFlags = 0 ' RESERVED, must stay 0
  29. ' ** Parse Command Line
  30. ' Loop through arguments
  31. While ArgCount < Wscript.Arguments.Count
  32. ' Determine switches used
  33. Select Case Wscript.Arguments(ArgCount)
  34. Case "-v": ' Designate backup version number
  35. ' Move to next arg, which should be parameter
  36. ArgCount = ArgCount + 1
  37. If ArgCount => Wscript.Arguments.Count Then
  38. Call UsageMsg
  39. Else
  40. BuVersion = Wscript.Arguments(Argcount)
  41. End If
  42. Case "-?", "-h", "/?":
  43. Call UsageMsg
  44. Case Else:
  45. If BuName <> "SampleBackup" Then ' Only one name allowed
  46. Call UsageMsg
  47. Else
  48. BuName = Wscript.Arguments(ArgCount)
  49. End If
  50. End Select
  51. ' Move pointer to next argument
  52. ArgCount = ArgCount + 1
  53. Wend
  54. ' **Perform backup restore:
  55. ' First, create instance of computer object
  56. Set CompObj = GetObject("IIS://Localhost")
  57. ' Call Restore method
  58. ' NOTE: ** All IIS services will be stopped by this method, then restarted!
  59. Wscript.Echo "All services stopping ..."
  60. CompObj.Restore BuName, BuVersion, BuFlags ' NOTE: for restoration, BuFlags MUST be 0
  61. ' Make pretty version string
  62. If BuVersion = &HFFFFFFFE Then
  63. VersionMsg = "highest version"
  64. Else
  65. VersionMsg = "version " & BuVersion
  66. End If
  67. ' Check for error backing up Metabase
  68. If Err <> 0 Then 'Errors!
  69. If Err.Number = 5 Then ' Location name not available
  70. Wscript.Echo "Error restoring Metabase: '" & BuName & "' (" & VersionMsg & ") not available."
  71. Else
  72. Wscript.Echo "Error restoring Metabase from '" & BuName & "' (" & VersionMsg & ")."
  73. Wscript.Echo "Error number: " & Hex(Err.Number)
  74. End If
  75. Wscript.Echo "Services restarting."
  76. Else ' No errors!
  77. Wscript.Echo "Restored: Backup '" & BuName & "' (" & VersionMsg & ")."
  78. Wscript.Echo "Services restarted."
  79. End If
  80. ' Display usage messsage, then QUIT
  81. Sub UsageMsg
  82. Wscript.Echo "Usage: cscript metabackrest.vbs <backupname> [-v <versionnum>]"
  83. Wscript.Quit
  84. End Sub