BatchPatch Forums Home › Forums › BatchPatch Support Forum › Difficulty Creating VMware snapshots
- This topic has 5 replies, 3 voices, and was last updated 5 years, 4 months ago by renedevries.
-
AuthorPosts
-
June 18, 2019 at 8:21 pm #9375Magnus KnightParticipant
I want to be able to automate creating and removing snapshots for a VM in VMware, and I followed this guide provided by BatchPatch,
however this guide is using Hyper-V and when I try it for VMware it’s not working.
Is a powershell script (i.e. .ps1 script file) necessary for scripting VMware, or can BatchPatch do this on its own? I read in another thread where the powershell script can be called from within BatchPatch, but I feel like this is a simple task that I didn’t want to write a script then have to call it as an additional function.
This is the very basic method I’ve tried in BatchPatch, using a combination of “Create/modify remote commands” and a “Job Queue”. The commands in quotes work fine when I run them directly in Powershell, but they’re not working in BatchPatch.
cmd.exe /c echo . | powershell.exe -ExecutionPolicy Bypass -command "Connect-VIServer -Server vCenter.domain.com"
cmd.exe /c echo . | powershell.exe -ExecutionPolicy Bypass -command "New-Snapshot -VM VM1 -Name Pre-Patch"
June 18, 2019 at 8:47 pm #11637dougModeratorI don’t have a VMWare server to test with, but it appears that the first command that you are executing establishes a connection, and then the second command instructs the server to create the snapshot. Since the second command appears to be dependent on the connection first being established with the first command, you wouldn’t be able to run these successfully as two separate commands in BatchPatch. There will likely be no context for the second command because the first command was completely independently run. My guess is it will probably work to chain the two commands together into a single command using the semi-colon like this:
cmd.exe /c echo . | powershell.exe -ExecutionPolicy Bypass -command "Connect-VIServer -Server vCenter.domain.com; New-Snapshot -VM VM1 -Name Pre-Patch"
Alternatively you can put them in a .ps1 script file and then create a BatchPatch deployment for the .ps1 script file. Then include the deployment as part of your job queue.
June 19, 2019 at 4:13 pm #11638Magnus KnightParticipantThanks for the feedback Doug!
I was thinking the same thing about the second command not having an authenticated session established and it failing, and I also proved that by testing it manually in a command-line. I was hoping that an idea like the semicolon chain you provided would work, that is what I was looking for, but unfortunately it did not. I’m going to have to use the .ps1 script to do what I need. I feel it’s a bit more inefficient to have to use a script for such a simple task as creating a snapshot, but that’s the only way I see to do it with VMware.
Thanks again for helping with this, and I’ve tested it and have it working by calling the .ps1 script.
June 19, 2019 at 4:23 pm #11639Magnus KnightParticipantI have one other question, that I believe is the final piece to my puzzle with patching these sensitive servers. I just asked here since I didn’t want to clutter up the forum with extra posts.
Some of the servers that need patching are business critical Microsoft SQL servers. If a patch breaks these servers, then business stops, which of course is very bad. If a patch breaks the SQL server, my plan is to just revert back to the VMware snapshot that I took before patching, and if everything works and nothing breaks then I delete the snapshot.
What I would like to be able to do in BatchPatch is query specific services on remote servers (such as “SQL Server (MSSQLSERVER)” and if the service is not started, then stop the job queue so that the snapshot is not deleted and I can try to fix the issue.
I see in the Job Queue there are options for Terminate/Abort queue if previous action fails, so I think there should be a way to leverage this to stop if I can create a failure condition for a specified stopped service, but that is where I seem to be stuck. A query can tell me if a service is stopped, but the query will succeed and not be a failure.
Is there anything I’m overlooking in BatchPatch that will allow me to terminate a Job Queue/Advanced Multi-Row Sequence if a specific service on a remote server doesn’t start?
June 19, 2019 at 4:35 pm #11640dougModeratorYou can use the example at this link for guidance. It doesn’t do *exactly* what you are trying to do, but it does something very similar. Essentially you just need to have your script return 0 if the service is started and a non-0 int (such as 1 or -1) if the service is stopped. If you use ‘Terminate queue if previous action fails/errors’ immediately after your script deployment, then it will terminate the queue if the script returns anything other than 0.
batchpatch-custom-script-integration-install-windows-updates-only-after-stopping-a-specified-service
August 17, 2019 at 1:24 pm #11673renedevriesParticipantprobably you need VMware PowerCLI on the batchpatch machine to get this work.
-
AuthorPosts
- You must be logged in to reply to this topic.