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