This use case demonstrates using a PowerShell script to migrate an entire VTree from one storage pool to another. The volume in this example is a thin uncompressed volume. The storage pools are in the same protection domain, but this script can be modified to migrate between two different protection domains.
There are some restrictions when migrating volumes between storage pools with different layouts. For more information about the restrictions, consult the document Configure and Customize Dell PowerFlex.
Migrating a volume VTree consists of the following steps:
There are two storage pools in this example and the storage pool ids are hard coded in the script.
Use the following code to authenticate with PowerFlex Manager and initialize variables.
#PFMP ingress
$PFMPhost = "pfxm.powerflex.lab"
#Name of volume to be migrated
$Volume = "vol001"
#Initialize source and target storage pool variables
$SourceSP = ""
$TargetSP = ""
#Authentication
$Headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$Headers.Add("Content-Type", "application/json")
$Headers.Add("Accept", "application/json")
$CredJson = "{`"username`": `"admin`", `"password`": `"Password`"}"
$Response = Invoke-RestMethod "https://$PFMPhost/rest/auth/login" -Method POST -Headers $Headers -Body $CredJson
$accessToken = $Response.access_token
#Create authentication header for use in API calls
$AuthHeader = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$AuthHeader.Add("Content-Type", "application/json")
$AuthHeader.Add("Accept", "application/json")
$AuthHeader.Add("Authorization", "Bearer $accessToken")
The following code gets the identifiers for the volume to be migrated and the source storage pool. We also set the source and target storage pools.
#Query volume id from name
$VolJson = "{`"name`": `"$Volume`"}"
$VolumeID = (Invoke-RestMethod -Uri "https://$PFMPhost/api/types/Volume/instances/action/queryIdByKey" -Method POST -Body $VolJson -Headers $AuthHeader)
#Query for current storage pool
$SPJson = "{`"ids`": [`"$VolumeID`"]}"
$CurrentSP = (Invoke-RestMethod -Uri "https://$PFMPhost/api/types/Volume/instances/action/queryBySelectedIds" -Method POST -Body $SPJson -Headers $)
#Set source and target pools
$SourceSP = $CurrentSP.storagePoolId
if ($SourceSP -eq "c5d4313100000000")
{$TargetSP = "c5d4313200000001"}
else
{$TargetSP = "c5d4313100000000"}
The following code migrates the volume VTree to another storage pool and then records the action to a log file.
#Migrate volume from SourceSP to TargetSP
$TargetSPJson = "{`"destSPId`":`"$TargetSP`"}"
Invoke-RestMethod -Uri "https://$PFMPhost/api/instances/Volume::$VolumeID/action/migrateVTree" -Method POST -Body $TargetSPJson -Headers $AuthHeader
#Write to log file
#Format timestamp for logging
function Get-TimeStamp {
return "[{0:MM/dd/yy} {0:HH:mm:ss}]" -f (Get-Date)
}
#Write to log
Write-Output "$(Get-TimeStamp) Volume $Volume successfully migrated from storage pool $SourceSP to storage pool $TargetSP" | Out-File .\migratevolume.log -append