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.

114 lines
3.0 KiB

  1. '''''''''''''''''''''''''''''''''''''''''''''
  2. '
  3. ' Metabase Backup Utility
  4. '
  5. '''''''''''''''''''''''''''''''''''''''''''''
  6. ' Description:
  7. ' ------------
  8. ' This sample admin script allows you to create a backup of your Metabase.
  9. '
  10. ' To Run:
  11. ' -------
  12. ' This is the format for this script:
  13. '
  14. ' cscript metaback.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 = &HFFFFFFFF ' Use next available version number
  28. BuFlags = 0 ' No special flags
  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 "-F": ' Force overwrite, even if name and version exists
  43. BuFlags = 1
  44. Case "-h", "-?", "/?":
  45. Call UsageMsg
  46. Case Else:
  47. If BuName <> "SampleBackup" Then ' Only one name allowed
  48. Call UsageMsg
  49. Else
  50. BuName = Wscript.Arguments(ArgCount)
  51. End If
  52. End Select
  53. ' Move pointer to next argument
  54. ArgCount = ArgCount + 1
  55. Wend
  56. ' **Perform Backup:
  57. ' First, create instance of computer object
  58. Set CompObj = GetObject("IIS://Localhost")
  59. ' Call Backup method, with appropriate parameters
  60. CompObj.Backup BuName, BuVersion, BuFlags
  61. ' Make pretty version string
  62. If BuVersion = &HFFFFFFFF Then
  63. VersionMsg = "next 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 = &H80070050 Then ' Duplicate backup
  70. Wscript.Echo "'" & BuName & "' (version " & BuVersion & ") already exists. -F switch will causes existing version to be replaced."
  71. Else ' Something else went wrong
  72. Wscript.Echo "Error backing up Metabase to '" & BuName & "' (" & VersionMsg & ")."
  73. Wscript.Echo "Error number: " & Hex(Err.Number)
  74. End If
  75. Else ' No errors!
  76. If BuFlags = 1 Then ' Forced creation
  77. Wscript.Echo "Force created: Backup '" & BuName & "' (" & VersionMsg & ")."
  78. Else
  79. Wscript.Echo "Created: Backup '" & BuName & "' (" & VersionMsg & ")."
  80. End If
  81. End If
  82. ' Displays usage message, then QUITS
  83. Sub UsageMsg
  84. Wscript.Echo "Usage: cscript metaback.vbs [<backupname>][-v <versionnum>][-F (to force)]"
  85. Wscript.Quit
  86. End Sub