Microsoft Virtualization Discussions

New-NcVolClone suggestions for DR Recovery Script

bthurber
3,716 Views

I have to preface this by saying I'm new to powershell.  

 

Criteria:

I want to create a DR Recovery script that will flexclone snapmirrored volumes in our DR Controller based on the VolumeMirrorAttributes. 

 

Script:

$dr_vs0 = "net01"
$dr_vs1 = "net02"
$cluster = "net"
Connect-NcController $cluster -Vserver $dr_vs0
###################################
###################################

$dr_Attributes = Get-NcVol -VserverContext $dr_vs0 -Template
$dr_Query = Get-NcVol -Template
Initialize-NcObjectProperty -object $dr_Query -name VolumeMirrorAttributes
$dr_Query.VolumeMirrorAttributes.IsDataProtectionMirror = "True"
$dr_sm_volumes = Get-NcVol -Attributes $dr_Attributes -Query $dr_Query

$dr_clonevol = $dr_sm_volumes | Select-Object Name | ForEach-Object {$_.Name}

 

ForEach ($dr_i in $dr_clonevol) {

New-NcVolClone -CloneVolume $dr_vol"" -VserverContext $dr_vs0 -ParentVolume $dr_vol -SpaceReserve none 

}

 

How would I pass the variable "$dr_clonevol" in to the ForEach loop and use it to name the cloned volume in the -CloneVolume parameter?

 

I keep getting "New-NcVolClone : Cannot bind argument to parameter 'ParentVolume' because it is null."

 

echo $dr_clonevol
vs1_data_xpd_2hr_01_mirror
vs1_data_xpd_2hr_04_mirror
vs1_data_xpd_2hr_05_mirror
vs1_vs1_data_xpd_2hr_02_mirror
vs1_vs1_data_xpd_2hr_03_mirror

 

 

Thanks in advance!!!

1 ACCEPTED SOLUTION

Aparajita
3,696 Views

Hi,

 

I don't see the variable dr_vol being defined anywhere (assuming you've posted the entire script). That is the reason you're getting the "Can not bind" error - $dr_vol is in fact null.

 

As far as getting the cloneVol names in the for-each loop, I would suggest

 

$dr_sm_volumes = Get-NcVol -Attributes $dr_Attributes -Query $dr_Query

ForEach ($dr_clonevol in $dr_sm_volumes) {
     New-NcVolClone -CloneVolume $dr_clonevol.Name -VserverContext $dr_vs0 -ParentVolume $dr_vol -SpaceReserve none 
}

But from your problem description, I think you want the output of Get-NcVol to be the parent volumes and create a clone as parent_vol_name_clone or something similar? In that case, I would suggest

 

$dr_sm_volumes = Get-NcVol -Attributes $dr_Attributes -Query $dr_Query

ForEach ($dr_vol in $dr_sm_volumes) {
     $dr_clonevol_name = $dr_vol.Name + "_clone";
     New-NcVolClone -CloneVolume $dr_clonevol_name -VserverContext $dr_vs0 -ParentVolume $dr_vol.Name -SpaceReserve none 
}

 

Hope this helps,

Aparajita

View solution in original post

3 REPLIES 3

Aparajita
3,697 Views

Hi,

 

I don't see the variable dr_vol being defined anywhere (assuming you've posted the entire script). That is the reason you're getting the "Can not bind" error - $dr_vol is in fact null.

 

As far as getting the cloneVol names in the for-each loop, I would suggest

 

$dr_sm_volumes = Get-NcVol -Attributes $dr_Attributes -Query $dr_Query

ForEach ($dr_clonevol in $dr_sm_volumes) {
     New-NcVolClone -CloneVolume $dr_clonevol.Name -VserverContext $dr_vs0 -ParentVolume $dr_vol -SpaceReserve none 
}

But from your problem description, I think you want the output of Get-NcVol to be the parent volumes and create a clone as parent_vol_name_clone or something similar? In that case, I would suggest

 

$dr_sm_volumes = Get-NcVol -Attributes $dr_Attributes -Query $dr_Query

ForEach ($dr_vol in $dr_sm_volumes) {
     $dr_clonevol_name = $dr_vol.Name + "_clone";
     New-NcVolClone -CloneVolume $dr_clonevol_name -VserverContext $dr_vs0 -ParentVolume $dr_vol.Name -SpaceReserve none 
}

 

Hope this helps,

Aparajita

BradT
3,668 Views

@Aparajita wrote:

Hi,

 

I don't see the variable dr_vol being defined anywhere (assuming you've posted the entire script). That is the reason you're getting the "Can not bind" error - $dr_vol is in fact null.

 

As far as getting the cloneVol names in the for-each loop, I would suggest

 

$dr_sm_volumes = Get-NcVol -Attributes $dr_Attributes -Query $dr_Query

ForEach ($dr_clonevol in $dr_sm_volumes) {
     New-NcVolClone -CloneVolume $dr_clonevol.Name -VserverContext $dr_vs0 -ParentVolume $dr_vol -SpaceReserve none 
}

But from your problem description, I think you want the output of Get-NcVol to be the parent volumes and create a clone as parent_vol_name_clone or something similar? In that case, I would suggest

 

$dr_sm_volumes = Get-NcVol -Attributes $dr_Attributes -Query $dr_Query

ForEach ($dr_vol in $dr_sm_volumes) {
     $dr_clonevol_name = $dr_vol.Name + "_clone";
     New-NcVolClone -CloneVolume $dr_clonevol_name -VserverContext $dr_vs0 -ParentVolume $dr_vol.Name -SpaceReserve none 
}

 

Hope this helps,

Aparajita


I didn't include the intire script, only the final "at wits end" attempt but you obviously got the gist of what I was attempting to do.  I ran with your recommendation and got the following error:

 

New-NcVolClone : Clone of a DP volume vs1_data_xpd_2hr_01_mirror cannot be created without snapshot. Please provide snapshot

 

I made the following modification:

 

 

ForEach ($dr_vol in $dr_sm_volumes) {
     
     $getsnap = Get-NcSnapshot -Volume $dr_vol.Name | sort Created -Descending
     $getsnap_snap0 = $getsnap[0]
     
     $dr_clonevol_name = $dr_vol.Name + "_DR_Test";
     New-NcVolClone -CloneVolume $dr_clonevol_name -VserverContext $dr_vs0 -ParentVolume $dr_vol.Name -SpaceReserve none -ParentSnapshot $getsnap_snap0
}

 This worked perfectly... the takeaway being the .Name after the variable.  I don't understand why it's required - is this something you learn as you go? Smiley Happy

 

 

Thanks!

Aparajita
3,664 Views
It's pretty intuitive once you get used to "everything is an object, or should be" philosophy of PowerShell (takes a while if you're used to a *nix shell).

The output of Get-NcVol is an array of objects. So $dr_vol inside the foreach is an object. But the ParentVolume parameter of New-NcClone doesn't take a volume object, only a string value for the name. Hence the .Name to dereference the proper attribute of the $dr_vol object.
Public