PowerShell script exchange
Post Reply
ratkinsonuk
Expert
Posts: 102
Liked: 14 times
Joined: Dec 10, 2018 10:59 am
Full Name: Robert Atkinson
Contact:

Add-VBRScaleOutBackupRepository Automation Issues

Post by ratkinsonuk »

I'm writing a script to migrate on-prem backup storage to something more cloud based, but I have 2 issues. I thought I'd bring them here first to get R&D's take on this, as I suspect it'll require some development to add extra functionality. By the way, we're running B&R v11 cmdlets.


1) The cmdlet stops and asks for input
2) The cmdlet executes the task without returning back to the script/prompt


1) When the performance tier of the SOBR is already part of a backup, the cmdlet stops and prompts with

Code: Select all

Confirm
All jobs and backups using this extent will be automatically updated to point to the scale-out backup repository.
Proceed?

[Job] DEV_WEEKLY_CRM_BACKUP
[Job] PROD_DAILY_CRM_BACKUP
[Backup] PROD_DAILY_CRM_BACKUP
[Backup] DEV_WEEKLY_CRM_BACKUP
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"):
I can work around this by using -force, but I'm worried what other issues I might be telling it to ignore. Is there another switch or method I can respond 'Yes' to this prompt?


2) Upon successful verification of the input, the cmdlet creates the SOBR, but then goes straight into an Offload routine. From the GUI, you can simply click Close and leave the offload to run in the background. In Powershell, there isn't a 'nowait' option that I can see, so I have to wait potentially several hours before the offload completes and I can create the next SOBR.

Is there a way to return back to script execution and not wait for the offload?


Thanks, Rob.
HannesK
Product Manager
Posts: 14322
Liked: 2890 times
Joined: Sep 01, 2014 11:46 am
Full Name: Hannes Kasparick
Location: Austria
Contact:

Re: Add-VBRScaleOutBackupRepository Automation Issues

Post by HannesK »

Hello,

1) -force sounds good because it's what you want. The command would fail / error if something is really broken even with -force
2)
From the GUI, you can simply click Close and leave the offload to run in the background.
the PowerShell command should behave like the GUI. If the same happens in V12, then it might be worth to check with support.

I'm not a PowerShell expert, but there seem to be some options to start PowerShell commands without waiting for the result. Alternatively disabling the EnablePluginBackupOffload parameter should work.

Best regards,
Hannes
ratkinsonuk
Expert
Posts: 102
Liked: 14 times
Joined: Dec 10, 2018 10:59 am
Full Name: Robert Atkinson
Contact:

Re: Add-VBRScaleOutBackupRepository Automation Issues

Post by ratkinsonuk »

Thanks Hannes, those suggestions are excellent!

I'm still nervous about using '-force'. Are you able to take a look at the code and see what other scenarios this switch would trigger?

I'd spent quite a bit of time looking at start-process, but hadn't thought of using invoke-command. It's really this script example along with the 'using' scope that could make this work.

Code: Select all

using: - Used to access variables defined in another scope while running scripts via cmdlets like Start-Job and Invoke-Command.

The using: scope modifier

Using is a special scope modifier that identifies a local variable in a remote command. Without a modifier, PowerShell expects variables in remote commands to be defined in the remote session.

The using scope modifier is introduced in PowerShell 3.0.

For any script or command that executes out of session, you need the using scope modifier to embed variable values from the calling session scope, so that out of session code can access them. The using scope modifier is supported in the following contexts:

    Remotely executed commands, started with Invoke-Command using the ComputerName, HostName, SSHConnection or Session parameters (remote session)
    Background jobs, started with Start-Job (out-of-process session)
    Thread jobs, started via Start-ThreadJob or ForEach-Object -Parallel (separate thread session)

Depending on the context, embedded variable values are either independent copies of the data in the caller's scope or references to it. In remote and out-of-process sessions, they're always independent copies.

Code: Select all

# Create remote session on local machine
PS> $session = New-PSSession -cn localhost

# Start remote job
PS> $job = Invoke-Command -Session $session -ScriptBlock { 1..60 | % { sleep 1; "Output $_" } } -AsJob
PS> $job

Id     Name     PSJobTypeName   State         HasMoreData     Location      Command
--     ----     -------------   -----         -----------     --------      -------
1      Job1     RemoteJob       Running       True            localhost     1..60 | % { sleep 1; ...

# Disconnect the job session
PS> Disconnect-PSSession $session

Id Name         Transport ComputerName    ComputerType    State         ConfigurationName     Availability
-- ----         --------- ------------    ------------    -----         -----------------     ------------
1 Runspace1     WSMan     localhost       RemoteMachine   Disconnected  Microsoft.PowerShell          None

PS> $job

Id     Name     PSJobTypeName   State         HasMoreData     Location      Command
--     ----     -------------   -----         -----------     --------      -------
1      Job1     RemoteJob       Disconnected  True            localhost     1..60 | % { sleep 1;

# Reconnect the session to a new job object
PS> $jobNew = Receive-PSSession -Session $session -OutTarget Job
PS> $job | Wait-Job | Receive-Job
Output 9
Output 10
Output 11
...
I'll try and put together some code to try this out.

I'm also going to play with the EnablePluginBackupOffload switch. I'm wondering if I use the Set-VBRScaleOutBackupRepository cmdlet to enable this after I've created the repository if it will have the same 'hanging' effect. I suspect it will, but definitely worth trying.

The biggest problem is testing the options. Once the repository has been converted to a SOBR, it's very difficult to revert it back so that I can tune the code and test again.

Cheers, Rob.
ratkinsonuk
Expert
Posts: 102
Liked: 14 times
Joined: Dec 10, 2018 10:59 am
Full Name: Robert Atkinson
Contact:

Re: Add-VBRScaleOutBackupRepository Automation Issues

Post by ratkinsonuk »

One other note. I've been chatting with support (#06363264) and they're happy v12 doesn't have switches to control this behaviour, so we're raising an enhancement request together.

Cheers, Rob.
Post Reply

Who is online

Users browsing this forum: No registered users and 13 guests