PowerShell script exchange
Post Reply
getzjd
Enthusiast
Posts: 25
Liked: 3 times
Joined: Mar 12, 2012 3:10 am
Full Name: Jay
Location: Cincinnati, OH
Contact:

Script to Check Working status at remote site

Post by getzjd »

Let me preface this by saying that my knowledge of scripting is minimal and any script I develop usually ends up looking like a hack job :D

I am looking to piece together a script where:
Backup job at Site A starts
executes a script that will check a replication job at Site B to ensure it is not currently running.
It will then keep the backup job at Site A from executing until the replication job has finished.

I understand this will require some sort of invoke command
Invoke-Command -comp RepositoryFQDN -scriptblock {ScriptBlock} , as well as some sort of do while or do until loop that continues to check the status
( $Job = Get-VBRJob -name "Name of replication Job"
$Job.GetLastState() -eq "Working" ) of the remote job say every 60 minutes and once it sees the status as not working, then will allow the current job to proceed.

This will allow me to avoid the situation where a replication job may run several hours past the expected time. This only really occurs though on our 2 file servers that have Windows 2012 enabled which will, in turn, kick off a larger than normal incremental replication job occasionally based no the Windows 2012 deduplication/garbage collection/scrubbing process.

Thanks!
veremin
Product Manager
Posts: 20406
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Script to Check Working status at remote site

Post by veremin »

The following example should shed some light on how to check a job state and execute a second one in accordance:

Code: Select all

$Job = Get-VBRJob -name "Name of replication Job"
do{
Start-sleep -s 60
}while ($Job.GetLastState() -eq "Working")
Get-VBRJob -name "Name of second Job" | Start-VBRJob
Thanks.
getzjd
Enthusiast
Posts: 25
Liked: 3 times
Joined: Mar 12, 2012 3:10 am
Full Name: Jay
Location: Cincinnati, OH
Contact:

Re: Script to Check Working status at remote site

Post by getzjd »

I haven't had much time to test this, however, how would the call be handled when checking on remote servers? For example: Server A has backup job C that may run for an extended period of time. Server B has replication job D that shouldn't start until Backup job C on Server A is completed.

Again, excuse my ignorance on scripting.
Thanks
veremin
Product Manager
Posts: 20406
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Script to Check Working status at remote site

Post by veremin »

The best idea would be set a script as post activity for backup job C. Once the backup job C is finished, post-job activity will be started. Within the script connection to site B will be setup, and replication job D will be executed. Thanks.
Post Reply

Who is online

Users browsing this forum: No registered users and 12 guests