Script to stop application service in guest OS during backup

PowerShell script exchange

Script to stop application service in guest OS during backup

Veeam Logoby paulhadley » Fri Jan 17, 2014 9:33 am

Hi,

Apologies is if this isn't the correct place to enquire about this, but I was advised by Veeam support to ask here for help.

I need to backup a server that has application called Good for Enterprise installed using Veeam. Good Technology require that the 'GoodLinkServer' service is stopped on the server whilst it is backed up. This is required other wise the application is classed as unsupported. The server in question has a flat file database, I believe they wont the service stopped as they are trying to remove the risk of corruption on the DB.

I have tried using VM Tools quiescence to get this to work, however the script I am using only stops the service whilst the snapshot is creating then starts it straight after it is created, not for the duration of the backup or when removing the snapshot.

Current script for testing: C:\Program Files\VMware\VMware Tools\backupScripts.d\vcb.bat
if "%1%" == "freeze" goto doFreeze
if "%1%" == "freezeFail" goto doFreezeFail
if "%1%" == "thaw" goto doThaw

:doFreeze
C:\Windows\pre-freeze-script.bat
goto EOF

:doFreezeFail
C:\Windows\post-thaw-script.bat
goto EOF

:doThaw
C:\Windows\post-thaw-script.bat
goto EOF

:EOF

Can you advise how I may be able to stop the "GoodLinkServer" service for the duration of the backup please?
paulhadley
Novice
 
Posts: 5
Liked: never
Joined: Tue Nov 20, 2012 11:03 pm
Full Name: Paul Hadley

Re: Script to stop application service in guest OS during ba

Veeam Logoby Vitaliy S. » Fri Jan 17, 2014 10:11 am

Hi Paul,

paulhadley wrote:Good Technology require that the 'GoodLinkServer' service is stopped on the server whilst it is backed up

Just to make sure I understand the limitations of your application - when you create a VM snapshot with a stopped application service, this very VM image is transferred to the repository where VM backup file is created. So technically you have met the requirements that tell you to stop the service during backup. Keeping the service in question in a stopped state for the entire time required to copy the snapshot data should not be necessary, at least for applications with similar requirements.

Can you please confirm that you need to keep your application service in a stopped state when VM snapshot is committed?

Thanks!
Vitaliy S.
Veeam Software
 
Posts: 19558
Liked: 1102 times
Joined: Mon Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov

Re: Script to stop application service in guest OS during ba

Veeam Logoby paulhadley » Fri Jan 17, 2014 10:13 am

Yes. I will need to keep the application in a stopped state when the snapshot is committed. Is this possible?
paulhadley
Novice
 
Posts: 5
Liked: never
Joined: Tue Nov 20, 2012 11:03 pm
Full Name: Paul Hadley

Re: Script to stop application service in guest OS during ba

Veeam Logoby Vitaliy S. » Fri Jan 17, 2014 10:24 am

VMware Tools allow to execute scripts on pre-freeze and post-thaw operations, so the only way to achieve what you're after is to do the following:

1. Execute just a pre-freeze script via VMware Tools to stop the application service, don't run post-thaw scripts.
2. Once the job is complete, use a post-backup job option to execute the script that would start the service inside the backed up VM.

Should do the trick!
Vitaliy S.
Veeam Software
 
Posts: 19558
Liked: 1102 times
Joined: Mon Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov

Re: Script to stop application service in guest OS during ba

Veeam Logoby paulhadley » Fri Jan 17, 2014 10:33 am

That sounds like a good solution. With regards to post-backup job option are you talking about, Storage - Advanced settings - Advanced - Post job activity? Will this run a script inside my guest OS or locally on my VBR server?
paulhadley
Novice
 
Posts: 5
Liked: never
Joined: Tue Nov 20, 2012 11:03 pm
Full Name: Paul Hadley

Re: Script to stop application service in guest OS during ba

Veeam Logoby Vitaliy S. » Fri Jan 17, 2014 10:34 am

Yes, I'm referring to this option. It will execute a script on your backup server, however you can use something like PSexec to execute this script against the remote VM. Thanks!
Vitaliy S.
Veeam Software
 
Posts: 19558
Liked: 1102 times
Joined: Mon Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov

Re: Script to stop application service in guest OS during ba

Veeam Logoby paulhadley » Fri Jan 17, 2014 11:10 am

Ok, great. I can see how this would work with PSexec, however is it possible to do this without storing credentials and passing them in plain text?
paulhadley
Novice
 
Posts: 5
Liked: never
Joined: Tue Nov 20, 2012 11:03 pm
Full Name: Paul Hadley

Re: Script to stop application service in guest OS during ba

Veeam Logoby Vitaliy S. » Fri Jan 17, 2014 11:43 am

Quick google search returned me this article, you may want to give it a try: http://dereknewton.com/2010/06/psexec-p ... lear-text/
Vitaliy S.
Veeam Software
 
Posts: 19558
Liked: 1102 times
Joined: Mon Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov

Re: Script to stop application service in guest OS during ba

Veeam Logoby paulhadley » Tue Jan 21, 2014 3:22 pm

Hi Vitaliy,

Thanks for your help. I have has a look through the guide that you sent for PsExec passing credentials in clear text. But the problem is I wouldn't be allowed to store them in clear text on the management servers either. Then we had a thought of using windows scheduled tasks to manage the credentials side, but I cant get that to work unless I was logged on, even with the appropriate options in place.

My next thoughts are if it would be easier just to power down the VM, back it up and power it back on. But ideally I want an solution that is directly linked to the Veeam job. So rather than doing with with scheduled tasks in the vCenter. I could power it down using VMtools and a script in the guest OS. But is it possible that I could use a script to power on the VM with via Veeam - post job,if I gave the Veeam service account permissions in the vcenter?

Thanks,

Paul.
paulhadley
Novice
 
Posts: 5
Liked: never
Joined: Tue Nov 20, 2012 11:03 pm
Full Name: Paul Hadley

Re: Script to stop application service in guest OS during ba

Veeam Logoby v.Eremin » Wed Jan 22, 2014 7:46 am

You can use both PowerCLI and VeeamPSSnapin to achieve what you are after. So, within the script you should issue poweroff commands first (Stop-VM, then, execute backup job (Start-VM), and, finally, powerup VM (Start-VM). In order to power up/down VM you will have to connect to vCenter (Connect-VIServer), using valid credentials. The credentials can be stored be in secure way, and there are several ways how you can do it (1,2).

Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin


Return to PowerShell



Who is online

Users browsing this forum: No registered users and 3 guests