IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VBScript Discussion :

Script de sauvegarde


Sujet :

VBScript

  1. #1
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Juillet 2007
    Messages
    7
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2007
    Messages : 7
    Par défaut Script de sauvegarde
    salut à tous, actuellement, je suis en stage dans une boite d'informatique. Il n'y a qu'une seule serveur sous windows server 2003 qui sous VMware emule d'autres serveurs. je suis en train de mettre en place un systeme de sauvegarde.
    Mon directeur technique voudrait que la sauvegarde se déroule de la maniere suivante. La machine virtuel se met en pause sur VMware, ensuite, la sauvegarde se fait, puis la machine virtuelle se remet "en lecture", et on passe à une autre machine virtuelle. Vous pourriez me donner un script vbs qui me permettra de checker si un programme est toujours en execution, et si non de lancer un autre programme svp?

    Merci d'avance

    ps: si quelqun veut bien aussi me faire le script pour VMware, qui consiste a mettre la machine virtuelle en pause, ce serait super sympas

  2. #2
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Juillet 2007
    Messages
    7
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2007
    Messages : 7
    Par défaut
    bon, je commence à avancer, je réussi a mettre en pause, à lancer la sauvegarde quand la machine virutelle s'est enfin mis en pause, puis le remettre en lecture. le truc maintenant est d'arriver à ne pas relancer la machine virtual tant que le processus ubkernel.exe n'est pas terminé.
    voila le code, une fois que j'aurais trouvé comment verifier que le processus est terminer, il faudra que je trouve comment mettre en pause une seule machine virtuelle


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    '======================================
    '
    ' Description: VMware VmCOM 1.0 Type Library
    '
    ' Name: VMCOMLib
    ' Version: 1.0 [of Type Library]
    ' GUID: {0407CAC2-41D7-4EB4-898B-4EC06C57BB81}
    '
    ' File: VmCOM.dll
    ' Version: 1.0.0.1 [of file]
    '
    ' Extracted on: 2002.08.28 00:53:08
    '
    '=====================================
    ' VmErr
    '=====================================
    Const vmErr_ALREADYCONNECTED = -2147220980
    Const vmErr_BADRESPONSE = -2147220978
    Const vmErr_BADSTATE = -2147220984
    Const vmErr_BADVERSION = -2147220986
    Const vmErr_DISCONNECT = -2147220979
    Const vmErr_GARBAGE = -2147220977
    Const vmErr_INSUFFICIENT_RESOURCES = -2147220970
    Const vmErr_INVALIDARGS = -2147220989
    Const vmErr_INVALIDVM = -2147220974
    Const vmErr_NEEDINPUT = -2147220976
    Const vmErr_NETFAIL = -2147220990
    Const vmErr_NOACCESS = -2147220988
    Const vmErr_NOEXECVMAUTHD = -2147220983
    Const vmErr_NOMEM = -2147220991
    Const vmErr_NOPROPERTY = -2147220982
    Const vmErr_NOSUCHVM = -2147220981
    Const vmErr_NOTCONNECTED = -2147220987
    Const vmErr_NOTSUPPORTED = -2147220975
    Const vmErr_PROXYFAIL = -2147220969
    Const vmErr_TIMEOUT = -2147220985
    Const vmErr_UNSPECIFIED = -2147219993
    Const vmErr_VMBUSY = -2147220971
    Const vmErr_VMEXISTS = -2147220972
    Const vmErr_VMINITFAILED = -2147220973
    '=====================================
    ' VmExecutionState
    '=====================================
    Const vmExecutionState_Off = 2
    Const vmExecutionState_On = 1
    Const vmExecutionState_Stuck = 4
    Const vmExecutionState_Suspended = 3
    Const vmExecutionState_Unknown = 5
    '=====================================
    ' VmPlatform
    '=====================================
    Const vmPlatform_LINUX = 2
    Const vmPlatform_UNKNOWN = 4
    Const vmPlatform_VMNIX = 3
    Const vmPlatform_WINDOWS = 1
    '=====================================
    ' VmPowerOpMode
    '=====================================
    Const vmPowerOpMode_Hard = 1
    Const vmPowerOpMode_Soft = 2
    Const vmPowerOpMode_TrySoft = 3
    '=====================================
    ' VmProdInfoType
    '=====================================
    Const vmProdInfo_Build = 3
    Const vmProdInfo_Platform = 2
    Const vmProdInfo_Product = 1
    Const vmProdInfo_Version_Major = 4
    Const vmProdInfo_Version_Minor = 5
    Const vmProdInfo_Version_Revision = 6
    '=====================================
    ' VmProduct
    '=====================================
    Const vmProduct_ESX = 3
    Const vmProduct_GSX = 2
    Const vmProduct_UNKNOWN = 4
    Const vmProduct_WS = 1
    '=====================================
    ' VmTimeoutId
    '=====================================
    Const vmTimeoutId_Default = 1
    '
    ' VmCOM VBScript Sample Program 3
    ' Copyright 1998 VMware, Inc. All rights reserved. -- VMware Confidential
    '
    ' Permission is hereby granted, free of charge, to any person obtaining a
    ' copy of the software in this file (the "Software"), to deal in the
    ' Software without restriction, including without limitation the rights to
    ' use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    ' copies of the Software, and to permit persons to whom the Software is
    ' furnished to do so, subject to the following conditions:
    '
    ' The above copyright notice and this permission notice shall be included in
    ' all copies or substantial portions of the Software.
    '
    ' The names "VMware" and "VMware, Inc." must not be used to endorse or
    ' promote products derived from the Software without the prior written
    ' permission of VMware, Inc.
    '
    ' Products derived from the Software may not be called "VMware", nor may
    ' "VMware" appear in their name, without the prior written permission of
    ' VMware, Inc.
    '
    ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    ' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    ' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
    ' VMWARE,INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
    ' IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
    ' CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    '
    ' ------
    '
    ' This program is for educational purposes only.
    ' It is not to be used in production environments.
    '
    ' Description:
    '
    ' This script gets a list of virtual machines registered on
    ' the local server. It attempts to power-on each VM that
    ' is not already running and has a line in the config file:
    '
    ' autostart=true
    '
    '
    ' Instructions for Windows 2000 and Windows XP host:
    '
    ' - save the contents of this file to a file named 'sample3.vbs'
    '
    ' - there should be an accompanying file named 'sample3.wsf'
    ' It is placed in the same directory as this file during
    ' product installation. This file is responsible for setting
    ' up the Windows Script Host environment and loading the
    ' VmCOM type library, thereby enabling this script to
    ' reference symbolic constants such as vmExecutionState_On
    '
    ' - in a command line window, type:
    ' cscript //nologo sample3.wsf
    '
     
    Set connect_params = CreateObject("VmCOM.VmConnectParams")
     
    ' By default, connects to the local server.
    ' To connect to a remote server, uncomment these lines and set
    ' the values appropriately.
    '
    ' connect_params.hostname = "<host>"
    ' connect_params.username = "<user>"
    ' connect_params.password = "<password>"
    '
    ' And use this if your port number is different
    ' connect_params.port = 902
     
    Set vm_server = CreateObject("VmCOM.VmServerCtl")
     
    ' Handle errors non-fatally from here on
    On Error Resume Next
     
    '
    ' Try connecting to server a few times. It's possible the VMware services
    ' are still in the process of starting up. We'll wait a maximum of
    ' 12 * 10 = 120 seconds = 2 minutes
    '
    connected = false
    for tries = 1 to 12
     
    vm_server.Connect connect_params
    if Err.number = 0 then
    connected = true
    exit for
    end if
    WScript.Echo "Could not connect to server: " & Err.Description
    WScript.Echo "Retrying in 10 seconds ..."
    WScript.Sleep 10000
    Err.clear
    next
     
    if not connected then
    WScript.Echo "Failed to connect to server. Giving up."
    WScript.Quit
    end if
     
    ' Get a list of all VMs from the server.
    Set vmlist = vm_server.RegisteredVmNames
     
    for each config in vmlist
    ' Connect to the VM
    Set vm = CreateObject("VmCOM.VmCtl")
    vm.Connect connect_params, config
     
    if Err.Number <> 0 then
    WScript.Echo "Could not connect to VM " & config & ": " & Err.Description
    Err.Clear
    else
    ' Check that the VM should be started automatically
    auto_start = vm.Config("autostart")
    auto_start ="true"
    if Err.Number <> 0 then
    if Err.Number <> vmErr_NOPROPERTY then
    WScript.Echo "Could not read autostart variable: " & Err.Number & ": " & Err.Description
    else
    WScript.Echo "This VM is not configured for autostart: " & config
    end if
    Err.Clear
    else
    if auto_start = "true" or auto_start = "TRUE" or auto_start = "poweron" then
    ' Check that the VM is powered off
     
    power_state = vm.ExecutionState
    if Err.Number <> 0 then
    WScript.Echo "Error getting execution state: " & Err.Number & ": " & Err.Description
    Err.Clear
    Else
     
    if power_state = vmExecutionState_Off or power_state = vmExecutionState_On then
     
    vm.Suspend(vmPowerOpMode_Hard)
    if Err.Number <> 0 then
    WScript.Echo "Error powering on " & config & ": " & Err.Description
    Err.Clear
    else
    ' Wait between starting up VMs to smooth out the load on the server
    WScript.Sleep 5000
    end if
    end if
    end if
    end if
    end if
    end if
     
    Next
     
    Do While vm.ExecutionState<> vmExecutionState_Suspended
     
     
    Sleep(100)
    Loop
     
     
     
     
    Dim oShell
     
    Set oShell = WScript.CreateObject ("WSCript.shell")
     
    oShell.run "test.ub4"
     
     
    '
    ' VmCOM VBScript Sample Program 3
    ' Copyright 1998 VMware, Inc. All rights reserved. -- VMware Confidential
    '
    ' Permission is hereby granted, free of charge, to any person obtaining a
    ' copy of the software in this file (the "Software"), to deal in the
    ' Software without restriction, including without limitation the rights to
    ' use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    ' copies of the Software, and to permit persons to whom the Software is
    ' furnished to do so, subject to the following conditions:
    '
    ' The above copyright notice and this permission notice shall be included in
    ' all copies or substantial portions of the Software.
    '
    ' The names "VMware" and "VMware, Inc." must not be used to endorse or
    ' promote products derived from the Software without the prior written
    ' permission of VMware, Inc.
    '
    ' Products derived from the Software may not be called "VMware", nor may
    ' "VMware" appear in their name, without the prior written permission of
    ' VMware, Inc.
    '
    ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    ' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    ' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
    ' VMWARE,INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
    ' IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
    ' CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    '
    ' ------
    '
    ' This program is for educational purposes only.
    ' It is not to be used in production environments.
    '
    ' Description:
    '
    ' This script gets a list of virtual machines registered on
    ' the local server. It attempts to power-on each VM that
    ' is not already running and has a line in the config file:
    '
    ' autostart=true
    '
    '
    ' Instructions for Windows 2000 and Windows XP host:
    '
    ' - save the contents of this file to a file named 'sample3.vbs'
    '
    ' - there should be an accompanying file named 'sample3.wsf'
    ' It is placed in the same directory as this file during
    ' product installation. This file is responsible for setting
    ' up the Windows Script Host environment and loading the
    ' VmCOM type library, thereby enabling this script to
    ' reference symbolic constants such as vmExecutionState_On
    '
    ' - in a command line window, type:
    ' cscript //nologo sample3.wsf
    '
     
    Set connect_params = CreateObject("VmCOM.VmConnectParams")
     
    ' By default, connects to the local server.
    ' To connect to a remote server, uncomment these lines and set
    ' the values appropriately.
    '
    ' connect_params.hostname = "<host>"
    ' connect_params.username = "<user>"
    ' connect_params.password = "<password>"
    '
    ' And use this if your port number is different
    ' connect_params.port = 902
     
    Set vm_server = CreateObject("VmCOM.VmServerCtl")
     
    ' Handle errors non-fatally from here on
    On Error Resume Next
     
    '
    ' Try connecting to server a few times. It's possible the VMware services
    ' are still in the process of starting up. We'll wait a maximum of
    ' 12 * 10 = 120 seconds = 2 minutes
    '
    connected = false
    for tries = 1 to 12
     
    vm_server.Connect connect_params
    if Err.number = 0 then
    connected = true
    exit for
    end if
    WScript.Echo "Could not connect to server: " & Err.Description
    WScript.Echo "Retrying in 10 seconds ..."
    WScript.Sleep 10000
    Err.clear
    next
     
    if not connected then
    WScript.Echo "Failed to connect to server. Giving up."
    WScript.Quit
    end if
     
    ' Get a list of all VMs from the server.
    Set vmlist = vm_server.RegisteredVmNames
     
    for each config in vmlist
    ' Connect to the VM
    Set vm = CreateObject("VmCOM.VmCtl")
    vm.Connect connect_params, config
     
    if Err.Number <> 0 then
    WScript.Echo "Could not connect to VM " & config & ": " & Err.Description
    Err.Clear
    else
    ' Check that the VM should be started automatically
    auto_start = vm.Config("autostart")
    auto_start ="true"
    if Err.Number <> 0 then
    if Err.Number <> vmErr_NOPROPERTY then
    WScript.Echo "Could not read autostart variable: " & Err.Number & ": " & Err.Description
    else
    WScript.Echo "This VM is not configured for autostart: " & config
    end if
    Err.Clear
    else
    if auto_start = "true" or auto_start = "TRUE" or auto_start = "poweron" then
    ' Check that the VM is powered off
     
    power_state = vm.ExecutionState
    if Err.Number <> 0 then
    WScript.Echo "Error getting execution state: " & Err.Number & ": " & Err.Description
    Err.Clear
    Else
     
    if power_state = vmExecutionState_Off or power_state = vmExecutionState_Suspended then
     
    vm.Start(vmPowerOpMode_Soft)
    if Err.Number <> 0 then
    WScript.Echo "Error powering on " & config & ": " & Err.Description
    Err.Clear
    else
    ' Wait between starting up VMs to smooth out the load on the server
    WScript.Sleep 5000
    end if
    end if
    end if
    end if
    end if
    end if
     
    next

  3. #3
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Juillet 2007
    Messages
    7
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2007
    Messages : 7
    Par défaut
    c'est bon, j'ai presque fini mon script, il ne me reste plus qu'a faire en sorte que telle ou telle machine virtuelle se mette en pause^^

    je vous mets le script presque fini
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    '=====================================
    ' VmErr
    '=====================================
    Const vmErr_ALREADYCONNECTED = -2147220980
    Const vmErr_BADRESPONSE = -2147220978
    Const vmErr_BADSTATE = -2147220984
    Const vmErr_BADVERSION = -2147220986
    Const vmErr_DISCONNECT = -2147220979
    Const vmErr_GARBAGE = -2147220977
    Const vmErr_INSUFFICIENT_RESOURCES = -2147220970
    Const vmErr_INVALIDARGS = -2147220989
    Const vmErr_INVALIDVM = -2147220974
    Const vmErr_NEEDINPUT = -2147220976
    Const vmErr_NETFAIL = -2147220990
    Const vmErr_NOACCESS = -2147220988
    Const vmErr_NOEXECVMAUTHD = -2147220983
    Const vmErr_NOMEM = -2147220991
    Const vmErr_NOPROPERTY = -2147220982
    Const vmErr_NOSUCHVM = -2147220981
    Const vmErr_NOTCONNECTED = -2147220987
    Const vmErr_NOTSUPPORTED = -2147220975
    Const vmErr_PROXYFAIL = -2147220969
    Const vmErr_TIMEOUT = -2147220985
    Const vmErr_UNSPECIFIED = -2147219993
    Const vmErr_VMBUSY = -2147220971
    Const vmErr_VMEXISTS = -2147220972
    Const vmErr_VMINITFAILED = -2147220973
    '=====================================
    ' VmExecutionState
    '=====================================
    Const vmExecutionState_Off = 2
    Const vmExecutionState_On = 1
    Const vmExecutionState_Stuck = 4
    Const vmExecutionState_Suspended = 3
    Const vmExecutionState_Unknown = 5
    '=====================================
    ' VmPlatform
    '=====================================
    Const vmPlatform_LINUX = 2
    Const vmPlatform_UNKNOWN = 4
    Const vmPlatform_VMNIX = 3
    Const vmPlatform_WINDOWS = 1
    '=====================================
    ' VmPowerOpMode
    '=====================================
    Const vmPowerOpMode_Hard = 1
    Const vmPowerOpMode_Soft = 2
    Const vmPowerOpMode_TrySoft = 3
    '=====================================
    ' VmProdInfoType
    '=====================================
    Const vmProdInfo_Build = 3
    Const vmProdInfo_Platform = 2
    Const vmProdInfo_Product = 1
    Const vmProdInfo_Version_Major = 4
    Const vmProdInfo_Version_Minor = 5
    Const vmProdInfo_Version_Revision = 6
    '=====================================
    ' VmProduct
    '=====================================
    Const vmProduct_ESX = 3
    Const vmProduct_GSX = 2
    Const vmProduct_UNKNOWN = 4
    Const vmProduct_WS = 1
    '=====================================
    ' VmTimeoutId
    '=====================================
    Const vmTimeoutId_Default = 1
     
    Set connect_params = CreateObject("VmCOM.VmConnectParams")
     
    ' By default, connects to the local server.
    ' To connect to a remote server, uncomment these lines and set
    ' the values appropriately.
    '
    ' connect_params.hostname = "<host>"
    ' connect_params.username = "<user>"
    ' connect_params.password = "<password>"
    '
    ' And use this if your port number is different
    ' connect_params.port = 902
     
    Set vm_server = CreateObject("VmCOM.VmServerCtl")
     
    ' Handle errors non-fatally from here on
    On Error Resume Next
     
    '
    ' Try connecting to server a few times. It's possible the VMware services
    ' are still in the process of starting up. We'll wait a maximum of
    ' 12 * 10 = 120 seconds = 2 minutes
    '
    connected = false
    for tries = 1 to 12
     
       vm_server.Connect connect_params
       if Err.number = 0 then
          connected = true
          exit for
       end if
       WScript.Echo "Could not connect to server: " & Err.Description
       WScript.Echo "Retrying in 10 seconds ..."
       WScript.Sleep 10000
       Err.clear
    next
     
    if not connected then 
       WScript.Echo "Failed to connect to server. Giving up."
       WScript.Quit
    end if
     
    ' Get a list of all VMs from the server.
    Set vmlist = vm_server.RegisteredVmNames
     
    for each config in vmlist
       ' Connect to the VM
       Set vm = CreateObject("VmCOM.VmCtl")
       vm.Connect connect_params, config
     
       if Err.Number <> 0 then 
          WScript.Echo "Could not connect to VM " & config & ": " & Err.Description
          Err.Clear
       else
          ' Check that the VM should be started automatically
          auto_start = vm.Config("autostart")           'On peut essayer d'enlever les autostart =true
          auto_start ="true"
          if Err.Number <> 0 then
    	 if Err.Number <> vmErr_NOPROPERTY then 
    	    WScript.Echo "Could not read autostart variable: " & Err.Number & ": " & Err.Description
             else 
    	    WScript.Echo "This VM is not configured for autostart: " & config 
    	 end if
             Err.Clear
          else
    	 if auto_start = "true" or auto_start = "TRUE" or auto_start = "poweron" then
    	    ' Check that the VM is powered off
     
    	    power_state = vm.ExecutionState
    	    if Err.Number <> 0 then
    	       WScript.Echo "Error getting execution state: " & Err.Number & ": " & Err.Description
    	       Err.Clear
    	    Else
     
    	       if power_state = vmExecutionState_Off or power_state = vmExecutionState_On then
     
    		  vm.Suspend(vmPowerOpMode_Hard)
    		  if Err.Number <> 0 then
    		     WScript.Echo "Error powering on " & config & ": " & Err.Description
    		     Err.Clear
                      else 
                         ' Wait between starting up VMs to smooth out the load on the server
                         WScript.Sleep 5000
                      end if
    	       end if
    	    end if
    	 end if
          end if
       end if
     
    Next
     
    Do While vm.ExecutionState<> vmExecutionState_Suspended 'on demande au code de vérifier si la machine virtuelle est bien en pause
     
     
    Sleep(1000) 'on mets un sleep de 1 sec pour faire en sorte que la boucle ne se fasse pas trop souvent
    Loop
     
     
     
     
    Dim oShell 
     
    Set oShell = WScript.CreateObject ("WSCript.shell") 
     
    oShell.run "test.ub4" 'on ouvre le fichier de backup qui lui est déja configuré
    Sleep(10000) 'on mets un sleep de 10 sec pour faire en sorte que le programme de sauvegarde est le temps de se lancé
     
    Dim objWMIService, objProcess, colProcess
    Dim strComputer, strList
    Dim test
     
    copie_active=1
    strComputer = "."
    Do While (copie_active=1)
      Set objWMIService = GetObject("winmgmts:" _
      & "{impersonationLevel=impersonate}!\\" _
      & strComputer & "\root\cimv2")
     
      Set colProcess = objWMIService.ExecQuery _
      ("Select * from Win32_Process")
      copie_active=0
      For Each objProcess in colProcess
        strList = strList & vbCr & objProcess.Name
     
     
        if objProcess.Name="UbKernel.exe" Then 'le processus qui doit être fermé pour que le script continu est UbKernel.exe 
        copie_active=1
     
        End If
     
      Next
     
    loop 'la boucle recommence tant que UbKernel.exe n'est pas fermé
     
     Set connect_params = CreateObject("VmCOM.VmConnectParams")
     
    ' By default, connects to the local server.
    ' To connect to a remote server, uncomment these lines and set
    ' the values appropriately.
    '
    ' connect_params.hostname = "<host>"
    ' connect_params.username = "<user>"
    ' connect_params.password = "<password>"
    '
    ' And use this if your port number is different
    ' connect_params.port = 902
     
    Set vm_server = CreateObject("VmCOM.VmServerCtl")
     
    ' Handle errors non-fatally from here on
    On Error Resume Next
     
    '
    ' Try connecting to server a few times. It's possible the VMware services
    ' are still in the process of starting up. We'll wait a maximum of
    ' 12 * 10 = 120 seconds = 2 minutes
    '
    connected = false
    for tries = 1 to 12
     
       vm_server.Connect connect_params
       if Err.number = 0 then
          connected = true
          exit for
       end if
       WScript.Echo "Could not connect to server: " & Err.Description
       WScript.Echo "Retrying in 10 seconds ..."
       WScript.Sleep 10000
       Err.clear
    next
     
    if not connected then 
       WScript.Echo "Failed to connect to server. Giving up."
       WScript.Quit
    end if
     
    ' Get a list of all VMs from the server.
    Set vmlist = vm_server.RegisteredVmNames
     
    for each config in vmlist
       ' Connect to the VM
       Set vm = CreateObject("VmCOM.VmCtl")
       vm.Connect connect_params, config
     
       if Err.Number <> 0 then 
          WScript.Echo "Could not connect to VM " & config & ": " & Err.Description
          Err.Clear
       else
          ' Check that the VM should be started automatically
          auto_start = vm.Config("autostart")               'On peut essayer d'enlever les autostart =true
          auto_start ="true"
          if Err.Number <> 0 then
    	 if Err.Number <> vmErr_NOPROPERTY then 
    	    WScript.Echo "Could not read autostart variable: " & Err.Number & ": " & Err.Description
             else 
    	    WScript.Echo "This VM is not configured for autostart: " & config 
    	 end if
             Err.Clear
          else
    	 if auto_start = "true" or auto_start = "TRUE" or auto_start = "poweron" then
    	    ' Check that the VM is powered off
     
    	    power_state = vm.ExecutionState
    	    if Err.Number <> 0 then
    	       WScript.Echo "Error getting execution state: " & Err.Number & ": " & Err.Description
    	       Err.Clear
    	    Else
     
    	       if power_state = vmExecutionState_Off or power_state = vmExecutionState_Suspended then
     
    		  vm.Start(vmPowerOpMode_Soft)
    		  if Err.Number <> 0 then
    		     WScript.Echo "Error powering on " & config & ": " & Err.Description
    		     Err.Clear
                      else 
                         ' Wait between starting up VMs to smooth out the load on the server
                         WScript.Sleep 5000
                      end if
    	       end if
    	    end if
    	 end if
          end if
       end if
     
    next

  4. #4
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Juillet 2007
    Messages
    7
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2007
    Messages : 7
    Par défaut
    ça m'énerve, je n'arrive pas a faire en sorte que seulement une machine se lance :'(
    grrr.
    Help, I need somebody's help
    bon, voila déja pour savoir le nom de la machine virtuelle qui tourne, enfin je crois^^
    str = vm.GuestInfo("name")
    sa se place ou?

  5. #5
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Juillet 2007
    Messages
    7
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2007
    Messages : 7
    Par défaut
    voila, sa y est, j'ai fini ce script, si quelqun en a un jour besoin pour son boulot

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    '=====================================
    ' VmErr
    '=====================================
    Const vmErr_ALREADYCONNECTED = -2147220980
    Const vmErr_BADRESPONSE = -2147220978
    Const vmErr_BADSTATE = -2147220984
    Const vmErr_BADVERSION = -2147220986
    Const vmErr_DISCONNECT = -2147220979
    Const vmErr_GARBAGE = -2147220977
    Const vmErr_INSUFFICIENT_RESOURCES = -2147220970
    Const vmErr_INVALIDARGS = -2147220989
    Const vmErr_INVALIDVM = -2147220974
    Const vmErr_NEEDINPUT = -2147220976
    Const vmErr_NETFAIL = -2147220990
    Const vmErr_NOACCESS = -2147220988
    Const vmErr_NOEXECVMAUTHD = -2147220983
    Const vmErr_NOMEM = -2147220991
    Const vmErr_NOPROPERTY = -2147220982
    Const vmErr_NOSUCHVM = -2147220981
    Const vmErr_NOTCONNECTED = -2147220987
    Const vmErr_NOTSUPPORTED = -2147220975
    Const vmErr_PROXYFAIL = -2147220969
    Const vmErr_TIMEOUT = -2147220985
    Const vmErr_UNSPECIFIED = -2147219993
    Const vmErr_VMBUSY = -2147220971
    Const vmErr_VMEXISTS = -2147220972
    Const vmErr_VMINITFAILED = -2147220973
    '=====================================
    ' VmExecutionState
    '=====================================
    Const vmExecutionState_Off = 2
    Const vmExecutionState_On = 1
    Const vmExecutionState_Stuck = 4
    Const vmExecutionState_Suspended = 3
    Const vmExecutionState_Unknown = 5
    '=====================================
    ' VmPlatform
    '=====================================
    Const vmPlatform_LINUX = 2
    Const vmPlatform_UNKNOWN = 4
    Const vmPlatform_VMNIX = 3
    Const vmPlatform_WINDOWS = 1
    '=====================================
    ' VmPowerOpMode
    '=====================================
    Const vmPowerOpMode_Hard = 1
    Const vmPowerOpMode_Soft = 2
    Const vmPowerOpMode_TrySoft = 3
    '=====================================
    ' VmProdInfoType
    '=====================================
    Const vmProdInfo_Build = 3
    Const vmProdInfo_Platform = 2
    Const vmProdInfo_Product = 1
    Const vmProdInfo_Version_Major = 4
    Const vmProdInfo_Version_Minor = 5
    Const vmProdInfo_Version_Revision = 6
    '=====================================
    ' VmProduct
    '=====================================
    Const vmProduct_ESX = 3
    Const vmProduct_GSX = 2
    Const vmProduct_UNKNOWN = 4
    Const vmProduct_WS = 1
    '=====================================
    ' VmTimeoutId
    '=====================================
    Const vmTimeoutId_Default = 1
     
    Set connect_params = CreateObject("VmCOM.VmConnectParams")
     
    ' By default, connects to the local server.
    ' To connect to a remote server, uncomment these lines and set
    ' the values appropriately.
    '
    ' connect_params.hostname = "<host>"
    ' connect_params.username = "<user>"
    ' connect_params.password = "<password>"
    '
    ' And use this if your port number is different
    ' connect_params.port = 902
     
    Set vm_server = CreateObject("VmCOM.VmServerCtl")
     
    ' Handle errors non-fatally from here on
    On Error Resume Next
     
    '
    ' Try connecting to server a few times. It's possible the VMware services
    ' are still in the process of starting up. We'll wait a maximum of
    ' 12 * 10 = 120 seconds = 2 minutes
    '
    connected = false
    for tries = 1 to 12
     
       vm_server.Connect connect_params
       if Err.number = 0 then
          connected = true
          exit for
       end if
       WScript.Echo "Could not connect to server: " & Err.Description
       WScript.Echo "Retrying in 10 seconds ..."
       WScript.Sleep 10000
       Err.clear
    next
     
    if not connected then 
       WScript.Echo "Failed to connect to server. Giving up."
       WScript.Quit
    end if
     
    ' Get a list of all VMs from the server.
    Set vmlist = vm_server.RegisteredVmNames
     
    for each config in vmlist
       ' Connect to the VM
       Set vm = CreateObject("VmCOM.VmCtl")
       vm.Connect connect_params, config
     
       if Err.Number <> 0 then 
          WScript.Echo "Could not connect to VM " & config & ": " & Err.Description
          Err.Clear
       Else
       If InStr(vm.Config("displayName"),"Satu")<>0 Then
          ' Check that the VM should be started automatically
          auto_start = vm.Config("autostart")           'On peut essayer d'enlever les autostart =true
          auto_start ="true"
          if Err.Number <> 0 then
    	 if Err.Number <> vmErr_NOPROPERTY then 
    	    WScript.Echo "Could not read autostart variable: " & Err.Number & ": " & Err.Description
             else 
    	    WScript.Echo "This VM is not configured for autostart: " & config 
    	 end if
             Err.Clear
          else
    	 if auto_start = "true" or auto_start = "TRUE" or auto_start = "poweron" then
    	    ' Check that the VM is powered off
     
    	    power_state = vm.ExecutionState
    	    if Err.Number <> 0 then
    	       WScript.Echo "Error getting execution state: " & Err.Number & ": " & Err.Description
    	       Err.Clear
    	    Else
     
    	       if power_state = vmExecutionState_Off or power_state = vmExecutionState_On then
     
    		  vm.Suspend(vmPowerOpMode_Hard)
    		  if Err.Number <> 0 then
    		     WScript.Echo "Error powering on " & config & ": " & Err.Description
    		     Err.Clear
                      else 
                         ' Wait between starting up VMs to smooth out the load on the server
                         WScript.Sleep 5000
                      end if
    	       end if
    	    end if
    	 end if
          end if
       end If
       End If
     
    Next
     
    Do While vm.ExecutionState<> vmExecutionState_Suspended 'on demande au code de vérifier si la machine virtuelle est bien en pause
     
     
    Sleep(1000) 'on mets un sleep de 1 sec pour faire en sorte que la boucle ne se fasse pas trop souvent
    Loop
     
     
     
     
    Dim oShell 
     
    Set oShell = WScript.CreateObject ("WSCript.shell") 
     
    oShell.run "test.ub4" 'on ouvre le fichier de backup qui lui est déja configuré
    Sleep(10000) 'on mets un sleep de 10 sec pour faire en sorte que le programme de sauvegarde est le temps de se lancé
     
    Dim objWMIService, objProcess, colProcess
    Dim strComputer, strList
    Dim test
     
    copie_active=1
    strComputer = "."
    Do While (copie_active=1)
      Set objWMIService = GetObject("winmgmts:" _
      & "{impersonationLevel=impersonate}!\\" _
      & strComputer & "\root\cimv2")
     
      Set colProcess = objWMIService.ExecQuery _
      ("Select * from Win32_Process")
      copie_active=0
      For Each objProcess in colProcess
        strList = strList & vbCr & objProcess.Name
     
     
        if objProcess.Name="UbKernel.exe" Then 'le processus qui doit être fermé pour que le script continu est UbKernel.exe 
        copie_active=1
     
        End If
     
      Next
     
    loop 'la boucle recommence tant que UbKernel.exe n'est pas fermé
     
     Set connect_params = CreateObject("VmCOM.VmConnectParams")
     
    ' By default, connects to the local server.
    ' To connect to a remote server, uncomment these lines and set
    ' the values appropriately.
    '
    ' connect_params.hostname = "<host>"
    ' connect_params.username = "<user>"
    ' connect_params.password = "<password>"
    '
    ' And use this if your port number is different
    ' connect_params.port = 902
     
    Set vm_server = CreateObject("VmCOM.VmServerCtl")
     
    ' Handle errors non-fatally from here on
    On Error Resume Next
     
    '
    ' Try connecting to server a few times. It's possible the VMware services
    ' are still in the process of starting up. We'll wait a maximum of
    ' 12 * 10 = 120 seconds = 2 minutes
    '
    connected = false
    for tries = 1 to 12
     
       vm_server.Connect connect_params
       if Err.number = 0 then
          connected = true
          exit for
       end if
       WScript.Echo "Could not connect to server: " & Err.Description
       WScript.Echo "Retrying in 10 seconds ..."
       WScript.Sleep 10000
       Err.clear
    next
     
    if not connected then 
       WScript.Echo "Failed to connect to server. Giving up."
       WScript.Quit
    end if
     
    ' Get a list of all VMs from the server.
    Set vmlist = vm_server.RegisteredVmNames
     
    for each config in vmlist
       ' Connect to the VM
       Set vm = CreateObject("VmCOM.VmCtl")
       vm.Connect connect_params, config
     
       if Err.Number <> 0 then 
          WScript.Echo "Could not connect to VM " & config & ": " & Err.Description
          Err.Clear
       Else
       If InStr(vm.Config("displayName"),"Satu")<>0 Then
          ' Check that the VM should be started automatically
          auto_start = vm.Config("autostart")               'On peut essayer d'enlever les autostart =true
          auto_start ="true"
          if Err.Number <> 0 then
    	 if Err.Number <> vmErr_NOPROPERTY then 
    	    WScript.Echo "Could not read autostart variable: " & Err.Number & ": " & Err.Description
             else 
    	    WScript.Echo "This VM is not configured for autostart: " & config 
    	 end if
             Err.Clear
          else
    	 if auto_start = "true" or auto_start = "TRUE" or auto_start = "poweron" then
    	    ' Check that the VM is powered off
     
    	    power_state = vm.ExecutionState
    	    if Err.Number <> 0 then
    	       WScript.Echo "Error getting execution state: " & Err.Number & ": " & Err.Description
    	       Err.Clear
    	    Else
     
    	       if power_state = vmExecutionState_Off or power_state = vmExecutionState_Suspended then
     
    		  vm.Start(vmPowerOpMode_Soft)
    		  if Err.Number <> 0 then
    		     WScript.Echo "Error powering on " & config & ": " & Err.Description
    		     Err.Clear
                      else 
                         ' Wait between starting up VMs to smooth out the load on the server
                         WScript.Sleep 5000
                      end if
    	       end if
    	    end if
    	 end if
          end if
       end If
       End if
     
    next

  6. #6
    Membre averti
    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    30
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2007
    Messages : 30
    Par défaut
    Bonjour,
    merci d'avoir posté ton travail, j'ai quelque chose du même genre à faire.

    Membor

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Script pour sauvegarde OVH
    Par d10g3n dans le forum Linux
    Réponses: 6
    Dernier message: 18/12/2006, 16h09
  2. Shell script de sauvegarde
    Par marza dans le forum Shell et commandes GNU
    Réponses: 15
    Dernier message: 22/11/2006, 22h32
  3. Script de sauvegarde FTP
    Par goldorax113 dans le forum Développement
    Réponses: 5
    Dernier message: 09/11/2006, 11h08
  4. Script de sauvegarde sous REDHAT 7.3
    Par florfilla18 dans le forum Linux
    Réponses: 12
    Dernier message: 22/08/2006, 17h03
  5. erreur sur script de sauvegarde
    Par zouetchou dans le forum Langage
    Réponses: 5
    Dernier message: 08/12/2005, 08h50

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo