Stopping BExec services on remote (tape) server

PowerShell script exchange

Stopping BExec services on remote (tape) server

Veeam Logoby pkelly_sts » Tue Mar 08, 2016 9:47 am

I'm parallel running Veeam tape backups & BExec (can only get rid of BE once I now I fully understand Veeams tape side of things) but obviously conflict issues even though I have a dedicated tape library I can use.

So, right now I'd like to just run a pre-job to stop BExec services and a post-job to start them again.

So far I have enabled remoting on the physical tape server (B&R server is a dedicated VM) and I have a powershell script on the B&R server that will successfully start/stop the services simply by executing the script in a "standard" (as opposed to "run as administrator") powershell console so I know the whole remoting side of things is working perfectly.

However, the pre/post jobs are stating the script is executed but they obviously complete too quickly for it to actually have run so I'm not sure what I need to do differently to get Veeam to execute the scripts properly.

The stop script is simply this (start scipt is identical but obviously "Start-service"):

#############################
#Stop Backup Exec Services on <TAPE-SERVER>
get-service -Name BackupExecAgentBrowser -Computername <TAPE-SERVER> | Stop-service
get-service -Name BackupExecJobEngine -Computername <TAPE-SERVER> | Stop-service
get-service -Name BackupExecRPCService -Computername <TAPE-SERVER> | Stop-service
get-service -Name BackupExecDeviceMediaService -Computername <TAPE-SERVER> | Stop-service
get-service -Name BackupExecAgentAccelerator -Computername <TAPE-SERVER> | Stop-service
#############################

Note I don't seem to need "new-pssession" in the above code?

I'm not using any Veeam-specific code so presumably I don't need to Add-VeeamPsSnap either?

Any suggestions welcome (I only occasionally dabble in PS & generally cobble stuff together based on research but haven't found anything where Veeam stops remote services as I'd concede it's probably not a common requirement! :)
[New Sig: PLEASE get GFS tape support for incrementals!!!]
pkelly_sts
Expert
 
Posts: 504
Liked: 55 times
Joined: Thu Jun 13, 2013 10:08 am
Full Name: Paul Kelly

Re: Stopping BExec services on remote (tape) server

Veeam Logoby PTide » Wed Mar 09, 2016 10:58 am

Hi,

However, the pre/post jobs are stating the script is executed but they obviously complete too quickly for it to actually have run so I'm not sure what I need to do differently to get Veeam to execute the scripts properly.
Not sure what you mean by "too quickly"? Does veeam job starts earlier than your pre-job script manages to stop BE services? Please elaborate.

get-service -Name BackupExecAgentBrowser -Computername <TAPE-SERVER> | Stop-service
Might be a dumb question but have you tried issuing this command manually on your VBR server? Did it actually manage to stop remote BE service? The reason behind my question:

This part
Code: Select all
get-service -Name BackupExecAgentBrowser -Computername <TAPE-SERVER>
fetches the specified service from your tape server and treat it as an object, so far so good, but in this part

Code: Select all
 | Stop-service
You actually pipe that object to a local machine Stop-service cmdlet, instead of passing it to a remote machine. That is you might actually need new-pssession. There is also another way:

Code: Select all
Get-Service -Name SERVICENAME -ComputerName SERVERNAME | Set-Service -Status Running


I'm not using any Veeam-specific code so presumably I don't need to Add-VeeamPsSnap either?
Correct.

Thank you.
PTide
Veeam Software
 
Posts: 3079
Liked: 252 times
Joined: Tue May 19, 2015 1:46 pm

Re: Stopping BExec services on remote (tape) server

Veeam Logoby pkelly_sts » Wed Mar 09, 2016 11:08 am

Not sure what you mean by "too quickly"? Does veeam job starts earlier than your pre-job script manages to stop BE services? Please elaborate.
Sorry, I mean there's no wait/delay after the "Running pre-job script" - it immediately goes onto job processing, i.e. there's no wait for the services to stop (see below)

get-service -Name BackupExecAgentBrowser -Computername <TAPE-SERVER> | Stop-service
Might be a dumb question but have you tried issuing this command manually on your VBR server? Did it actually manage to stop remote BE service? The reason behind my question:
Perfectly reasonable question: Yes I have. I opened a basic (non-admin) Powershell console & dragged the script into it. It runs perfectly & it outputs feedback such as "Stopping service <servicename>... with a delay between each one so takes, maybe, 10-15 seconds to stop all services, so this is the delay I'd have expected the script to run for before going into the next stage of the job (actually processing files etc.)

<...>You actually pipe that object to a local machine Stop-service cmdlet, instead of passing it to a remote machine. That is you might actually need new-pssession<...>
Hmm, but as mentioned above, the code works perfectly if running in PS console?

Correct
Thanks for confirmation.

Thank you.
[New Sig: PLEASE get GFS tape support for incrementals!!!]
pkelly_sts
Expert
 
Posts: 504
Liked: 55 times
Joined: Thu Jun 13, 2013 10:08 am
Full Name: Paul Kelly

Re: Stopping BExec services on remote (tape) server

Veeam Logoby pkelly_sts » Wed Mar 09, 2016 11:42 am 1 person likes this post

Actually I just had another play & thought I'd do a further test by copying & pasting the exact line of the job into a cmd shell (i.e. running powershell with the script as an argument) and spotted a flaw that I'd created when simplifying the script (I've changed it to specify the target BExec server as an argument) and discovered that I'd entered the script incorrectly as:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noninteractive -file "C:\Scripts\BEStart.ps1 <servername>"
Where it needed to be:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noninteractive -file "C:\Scripts\BEStart.ps1" <servername>

(last quote in different place)

That also runs perfectly now in CMD shell and no longer generates an error in the Veeam job but having made that modification I noticed something.

1) Editing the job caused it to restart (it's a continuous job) which caused the pre-job script to run & it reported sucessful running
2) It's now (expectedly) "Waiting for new restore points..." but no post-job script has run.

So, potentially if my script was working (the services weren't stopped after the job restart above) then it would now be sitting with all BExec services stopped, & only restart them after the next copy cycle?

This doesn't feel right to me at all, I'd have thought the pre/post should happen immediately surrounding any "movement" of the job, or am I missing something?
[New Sig: PLEASE get GFS tape support for incrementals!!!]
pkelly_sts
Expert
 
Posts: 504
Liked: 55 times
Joined: Thu Jun 13, 2013 10:08 am
Full Name: Paul Kelly

Re: Stopping BExec services on remote (tape) server

Veeam Logoby PTide » Wed Mar 09, 2016 11:57 am

Hmm, but as mentioned above, the code works perfectly if running in PS console?
True. Just tested it myself - it seems that the code works differently depending on a PS version.

1) Editing the job caused it to restart (it's a continuous job) which caused the pre-job script to run & it reported sucessful running
2) It's now (expectedly) "Waiting for new restore points..." but no post-job script has run.
Just want to make sure I got it right - in which job did you specify your pre/post job scripts? Is it a simple Backup job?

Thank you.
PTide
Veeam Software
 
Posts: 3079
Liked: 252 times
Joined: Tue May 19, 2015 1:46 pm

Re: Stopping BExec services on remote (tape) server

Veeam Logoby pkelly_sts » Wed Mar 09, 2016 12:03 pm

Using v1 to execute the scripts in both places.

This is all in a "Backups to Tape" job, source being local job / repository.
[New Sig: PLEASE get GFS tape support for incrementals!!!]
pkelly_sts
Expert
 
Posts: 504
Liked: 55 times
Joined: Thu Jun 13, 2013 10:08 am
Full Name: Paul Kelly

Re: Stopping BExec services on remote (tape) server

Veeam Logoby PTide » Wed Mar 09, 2016 2:55 pm

So, potentially if my script was working (the services weren't stopped after the job restart above) then it would now be sitting with all BExec services stopped, & only restart them after the next copy cycle?
Correct. So your prejob script has succesfully started though BE services are still running?

It's now (expectedly) "Waiting for new restore points..." but no post-job script has run.
If no post-job script will be executed after a copy cycle finishes then you can contact our support team and post post your case ID in this thread.

Thank you.
PTide
Veeam Software
 
Posts: 3079
Liked: 252 times
Joined: Tue May 19, 2015 1:46 pm

Re: Stopping BExec services on remote (tape) server

Veeam Logoby pkelly_sts » Wed Mar 09, 2016 3:11 pm

Yes, Script reported as "Pre-job script completed successfully", and I have a debug line in it writing to a (local) log file to confirm that it has executed, but the service is still running.

The next line in job status is "Waiting for new restore points".

I'll have to hold off logging a call as I logged a different one yesterday & so today was asked by support to update to Patch 3 which I've scheduled for tomorrow evening. So I shall test again after that patch & if not fixed, log another case & report back here.

Thanks for your input...
[New Sig: PLEASE get GFS tape support for incrementals!!!]
pkelly_sts
Expert
 
Posts: 504
Liked: 55 times
Joined: Thu Jun 13, 2013 10:08 am
Full Name: Paul Kelly

Re: Stopping BExec services on remote (tape) server

Veeam Logoby pkelly_sts » Wed Mar 09, 2016 4:28 pm

Out of interest I looked into the version difference issue you mentioned as I have seen it mentioned elsewhere so to test against that issue further I used the following in my script:

$svc = Get-Service -Name bedbg -ComputerName $beserver
Stop-Service -InputObject $svc

It didn't make any difference but to force the script to run I stopped & started the job manually, somehow I ended up disabling it & noted that, when starting it from a disabled state, although it still didnt stop the service, the steps performed exactly as I'd expect them to:

Job started...
Pre-job script...
No new files...
Post job script...
Job finished.
[New Sig: PLEASE get GFS tape support for incrementals!!!]
pkelly_sts
Expert
 
Posts: 504
Liked: 55 times
Joined: Thu Jun 13, 2013 10:08 am
Full Name: Paul Kelly

Re: Stopping BExec services on remote (tape) server

Veeam Logoby PTide » Thu Mar 10, 2016 5:04 pm

Could you please try to call your .ps1 via a separate .bat ? In other words specify .bat file as a pre-job script file and place "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noninteractive -file "C:\Scripts\BEStart.ps1" inside that .bat file. Also I think that placing a delay inside .bat is worth trying.

Thank you.
PTide
Veeam Software
 
Posts: 3079
Liked: 252 times
Joined: Tue May 19, 2015 1:46 pm

Re: Stopping BExec services on remote (tape) server

Veeam Logoby pkelly_sts » Mon Mar 14, 2016 10:51 am

OK, I've configured it via .bat file now so will see tonight.

Out of interest, how long a delay are you suggesting and for what purpose?
[New Sig: PLEASE get GFS tape support for incrementals!!!]
pkelly_sts
Expert
 
Posts: 504
Liked: 55 times
Joined: Thu Jun 13, 2013 10:08 am
Full Name: Paul Kelly

Re: Stopping BExec services on remote (tape) server

Veeam Logoby PTide » Mon Mar 14, 2016 11:01 am

Out of interest, how long a delay are you suggesting and for what purpose?
I believe that BExec services won't stop instantly after you've issued a stop-service command via powershell so placing a 10-15 secinds delay insise .bat file will make it to wait before starting the job. Another approach would be to place a loop that is constantly checking for BExec service status and terminates once all services are stopped.

OK, I've configured it via .bat file now so will see tonight.
Ok, looking forward to hear from you.

Thank you.
PTide
Veeam Software
 
Posts: 3079
Liked: 252 times
Joined: Tue May 19, 2015 1:46 pm

Re: Stopping BExec services on remote (tape) server

Veeam Logoby pkelly_sts » Tue Mar 15, 2016 11:05 am

OK, unfortunately no change except that at least the pre/post scripts no longer complain of timeouts. The scripts are executed (as I can see in my output to log file) but the services aren't touched.

Again, to confirm I dragged the .bat versions of the scripts into a "standard" (i.e. not "run as administrator") CMD prompt and they execute perfectly as-is.

I think it must be something to do with the context that Veeam is executing the scripts in?
[New Sig: PLEASE get GFS tape support for incrementals!!!]
pkelly_sts
Expert
 
Posts: 504
Liked: 55 times
Joined: Thu Jun 13, 2013 10:08 am
Full Name: Paul Kelly

Re: Stopping BExec services on remote (tape) server

Veeam Logoby v.Eremin » Mon Mar 21, 2016 2:25 pm

The scripts are executed under Veeam service account. As an additional check, it might be worth confirming (manually) whether the script does it job correctly, if executed under Veeam service account. Thanks.
v.Eremin
Veeam Software
 
Posts: 13433
Liked: 987 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Stopping BExec services on remote (tape) server

Veeam Logoby pkelly_sts » Tue Mar 22, 2016 10:51 am

I just logged into the B&R server directly as the service account, opened a standard CMD prompt (not run as admin) and successfully ran both the stop & start .bat files which stopped & started the remote BExec services as expected using the same .bat files specified in the pre/post-job options.
[New Sig: PLEASE get GFS tape support for incrementals!!!]
pkelly_sts
Expert
 
Posts: 504
Liked: 55 times
Joined: Thu Jun 13, 2013 10:08 am
Full Name: Paul Kelly

Next

Return to PowerShell



Who is online

Users browsing this forum: No registered users and 2 guests