cancel
Showing results for 
Search instead for 
Did you mean: 

BEMCLI - Script to restart services after backup jobs complete

OJanicki
Level 3

Hello.

Hoping this is pretty simple.  I'm looking for a PowerShell script which would only restart services (via Restart-BEService) once all active jobs are done.  I'll put this into a scheduled task and run once per day.

 

Thanks!

6 REPLIES 6

Sym-cr
Level 5

Check these two files in Backup Exec folder upon navigating to the installation directory.

Default Location: C:\Program Files\Symantec\Backup Exec\

File 1: BESTART.BAT

File 2: BESTOP.BAT

 

See if it helps in achieving what you need. Thanks!!

pkh
Moderator
Moderator
   VIP    Certified
Why do you need to restart the BE services daily?

OJanicki
Level 3

Sym-cr@zy, thanks but I'm looking for a method using PowerShell so I can query the current state of the jobs and ensure that they are not running when a restart happens.

pkh, the service restart is a workaround to using external USB hard drives as backup media.  I never found a mechanism to "eject" a USB HDD from Backup Exec, so I do a safe remove through Windows.  When I plug the next drive in, Backup Exec sees it and places it online, however when the job actually runs, it errors out and the drive gets placed in offline status.  The service restart avoids this, but a few jobs have failed when the restarts occurred in the midst of a job, so querying the jobs for their status prior to the Restart-BEService cmdlet would solve that.

Of course, if you have any insights on the original issue, that would be even better!

VJware
Level 6
Employee Accredited Certified

Instead of a service restart, you can add a pre-command to the first scheduled backup job to bring the disk storage online so that the backup doesn't fail with the disk being offline.

Sample pre-command:-

CD\
   powershell.exe -command "&{import-module bemcli;Get-BEDiskStorageDevice | Set-BEDiskStorageDevice -Disabled $false}"

 

pkh
Moderator
Moderator
   VIP    Certified
What version of BE are you using? When you safely eject the USB drive, does the disk storage on the disk goes offline and you get an alert telling you this? Is the USB drive plugged into the media server?

OJanicki
Level 3

VJware, thanks!  I will try that.

I played with BEMCLI and came up with this.  I think I'm close, but the loop seems to be infinite.  Any thoughts on how I can fix this?  The script is supposed to check for active jobs, wait until they are no longer active, then do a service restart.
 

# Init variable.

$ActiveJobs = Get-BEJob -IsActive $True

# Force a restart cycle when condition is met.

ForEach ($Job in $ActiveJobs)
{
	If ($Job.IsActive -eq $True)
	{
		Do
		{
			Echo $Job.Name " is active, waiting 10 seconds..."
			Sleep 10
		}
		Until ($Job.IsActive -eq $False)	
	}
}

Restart-BEService