How to Create cDOT Qtrees with Qtree Quotas from a CSV

Question/Scenario:
I have a load of trees that were created on another vendor’s storage (non-NetApp), each tree has a quota; how do I recreate all the qtrees and qtree quotas on cDOT, in readiness for migrating the data off?

Qtree and Quota Creator

The following script was created with the above scenario in mind. We’ve already created the volumes, so need an export of information from the old storage system regarding its Qtrees and Qtree Quotas, and then we can take this information and use it to create our Qtrees and Qtree Quotas on NetApp Clustered Data ONTAP (version 8.3.2 used in the examples).

In the screenshot below is an example of the content of the input CSV. Here we only consider Quota Hard Disk Limits (this could be expanded for other types of Qtree Quota limit.) The column headings in the CSV need to be as in the example (that is: “VOLUME”, “QTREE”, “QUOTA HARD LIMIT”, and “UNIT”).

Image: CSV Input to QtreeAndQuotaCreator

The following is an example of how to run Qtree and Quota Creator in PowerShell>


.\QtreeAndQuotaCreator.ps1 -UserName admin -Password YOURPASS -Cluster 10.0.1.100 -Vserver svm1 -CSVfile quota.csv


An example of the output is in the Appendix beneath the script.

The Script

Note: Formatted for blogger with tabs replaced by two spaces

Copy and paste the below into a text editor and save as QtreeAndQuotaCreator.ps1


############################################
## CREATE CDOT QTREES AND QUOTAS FROM CSV ##
############################################

<# CSV headings processed:
  "VOLUME","QTREE","QUOTA HARD LIMIT","UNIT"
  Note 1: For New-NcQtree, you can also specify
    -Mode -SecurityStyle -Oplocks -ExportPolicy
  Note 2: For Add/Set-NcQuota, you can also specify
    -FileLimit -Threshold -SoftDiskLimit -SoftFileLimit -PerformUserMapping
  Note 3: Units are kb/mb/gb...
#>

Param(
  [Parameter(Mandatory=$true)][String]$UserName,
  [Parameter(Mandatory=$true)][String]$Password,
  [Parameter(Mandatory=$true)][String]$Cluster,
  [Parameter(Mandatory=$true)][String]$Vserver,
  [Parameter(Mandatory=$true)][String]$CSVfile
)

## DISPLAY FUNCTION
Function Wr{
  Param([String]$Echo = "",[String]$Ink = "WHITE",[Switch]$EXIT)
  If($EXIT){ Write-Host $Echo -ForegroundColor RED; EXIT }
  Write-Host $Echo -ForegroundColor $Ink
}

## LOAD THE DATA ONTAP PSTK
If(!(Get-Module DataONTAP)){ [Void](Import-Module DataONTAP -ErrorAction SilentlyContinue) }
If(Get-Module DataONTAP){ Wr "Loaded DataONTAP PSTK" GREEN }
else{ Wr "Failed to load DataONTAP PSTK!" -EXIT }

## CONNECT TO CLUSTER
$SecPass = $Password | ConvertTo-SecureString -asPlainText -Force
$Cred = New-Object System.Management.Automation.PsCredential($UserName,$SecPass)
[Void](Connect-NcController $Cluster -Credential $Cred -ErrorAction SilentlyContinue)
If($Global:CurrentNcController){ Wr "Connected to $Cluster" GREEN}
else{ Wr "Failed to connnect to $Cluster!" -EXIT }

## CHECK VSERVER EXISTS
$GetNcVserver = Get-NcVserver $Vserver
If($GetNcVserver){ Wr "Verified vserver $Vserver" GREEN}
else{ Wr "Vserver $Vserver check failed!" -EXIT}

## GET LIST OF VOLUMES
$VolAttrs = Get-NcVol -Template
[System.Array]$Volumes = (Get-NcVol -Attributes $VolAttrs -VserverContext $Vserver).Name

## GET LIST OF VOLUMES WITH QUOTA ALREADY TURNED ON
$QuotaQuery = Get-NcQuotaStatus -Template
$QuotaQuery.Status = "on"
[System.Array]$VolsWithQuotaOn = (Get-NcQuotaStatus -Query $QuotaQuery -VserverContext $Vserver).Volume

## PROCESS THE CSV
If(Test-Path $CSVfile){ Wr "Tested path $CSVfile OK!" GREEN }
else{ Wr "Path check failed to $CSVfile!" -EXIT }
$CSVinput = Import-CSV -Path $CSVfile

## CREATE QTREES AND QUOTAS
$Quota_Pol = $GetNcVserver.QuotaPolicy # Current Quota Policy
$VolsToTurnQuotaOn = @() # Record volumes where quota needs to be turned on
$VolsToResizeQuota = @() # Record volumes where quota needs resize
$CSVinput | Foreach{
  If($Volumes -Contains $_.VOLUME){
    ## CREATING NEW QTREE
    [Void](New-NcQtree -Volume $_.VOLUME -Qtree $_.QTREE -VserverContext $Vserver -ErrorAction SilentlyContinue)   
    Wr ("Created Qtree " + $_.QTREE + " on volume " + $_.VOLUME) GREEN
    ## CREATING NEW QUOTA
    [Void](Add-NcQuota -Path ("/vol/" + $_.VOLUME + "/" + $_.QTREE) -DiskLimit ($_."QUOTA HARD LIMIT" + $_."UNIT") -Policy $Quota_Pol -VserverContext $Vserver -ErrorAction SilentlyContinue)
    [Void](Set-NcQuota -Path ("/vol/" + $_.VOLUME + "/" + $_.QTREE) -DiskLimit ($_."QUOTA HARD LIMIT" + $_."UNIT") -Policy $Quota_Pol -VserverContext $Vserver -ErrorAction SilentlyContinue)
    Wr ("Set Quota with hard limit of " + $_."QUOTA HARD LIMIT" + $_."UNIT") GREEN
    ## UPDATE VOL QUOTA ON/RESIZE ARRAYS
    If($VolsWithQuotaOn -Contains $_.VOLUME){
      If($VolsToTurnQuotaOn -NotContains $_.VOLUME){
        If($VolsToResizeQuota -NotContains $_.VOLUME){
          $VolsToResizeQuota += $_.VOLUME
        }
      }
    }else{
      $VolsWithQuotaOn += $_.VOLUME
      $VolsToTurnQuotaOn += $_.VOLUME
    }
  }else{
    Wr ("Volume " + $_.VOLUME + " does not exist!") RED
  }
}

## ENABLING QUOTAS
$VolsToTurnQuotaOn | Foreach{
  [Void](Enable-NcQuota -Volume $_ -VserverContext $Vserver)
  Wr "Enabled quota on volume $_" GREEN
}

## RESIZING QUOTAS
$VolsToResizeQuota | Foreach{
  [Void](Start-NcQuotaResize -Volume $_ -VserverContext $Vserver)
  Wr "Started quota resize on volume $_" GREEN
}

## OUTPUT QUOTA REPORT
Get-NcQuotaReport -Vserver $Vserver | Sort-Object QuotaTarget | FT QuotaType,QuotaTarget,DiskLimit -AutoSize
Wr "Newly created quotas can time a time to initialize. If newly created quotas are not in the report, please wait and then run PS>" CYAN
Wr "Get-NcQuotaReport -Vserver $Vserver | Sort-Object QuotaTarget | FT QuotaType,QuotaTarget,DiskLimit -AutoSize" YELLOW


Appendix: Example Output

Image: Example of running Qtree and Quota Creator

Comments

Post a Comment