Data Backup and Recovery

restoring a file from within a LUN

mrembas
4,569 Views

Hi

 

I have snapmirror implemeted between FAS and ontapselect. On ontap select I have DR  volume with MIrror and Vault policy.
My snapshoted volumes are SAN (iSCIS - LUNs) and the question is how to recover single file from snapshot for LUN volumes.
One of the aproach which I found is by :

file clone create -vserver vserver_name -volume volume_name -source-path source_path -snapshot-name snapshot_name -destination-path destination_path


But I realy have no Idea what I should put in source_path and destination path ? New name o volumes ?

Long long ago I can clone luns in simple way from snapshots but in netapp 9 ?

Is there any other method to recover files from snapshot ?

 

1 ACCEPTED SOLUTION

mbeattie
4,488 Views

Hi,

 

I tested the process in my lab, create a few LUNs, mapped them, formatted and mounted. Copied some data to a LUN, created a snapshot, deleted the data, then ran the following script which enabled me to restore the deleted files from the cloned LUN on the host.

 

The powershell code below will enable you to clone a source LUN and map it to an igroup based on a source snapshot name. I would recommend that you consider using WFA for this process instead of script but it's just an example for you. EG:

 

PS C:\Scripts\PowerShell\Projects\CreateLunClone> $credentials = Get-Credential -Credential admin
PS C:\Scripts\PowerShell\Projects\CreateLunClone> .\CreateLunClone.ps1 -Cluster cluster1.testlab.local -VserverName vserver3 -VolumeName iscsi_data_001 -SourcePath "/vol/iscsi_data_001/lun_001" -DestinationVolume iscsi_data_001 -Destination
Path "lun_001_clone" -Snapshot clonetest -SpaceReserved $false -IgroupName igroup_001 -Credentials $credentials
Executed Command: Connect-NcController -Name cluster1.testlab.local -HTTPS -Credential $credentials -ErrorAction Stop
Imported module "DataONTAP"
Executed Command: New-NcClone -Volume iscsi_data_001 -SourcePath lun_001 -DestinationPath lun_001_clone -Snapshot clonetest -DestinationVolume iscsi_data_001 -VserverContext vserver3 -ErrorAction Stop
Created clone of "/vol/iscsi_data_001/lun_001" on vserver "vserver3"
Executed Command: Add-NcLunMap -Path "/vol/iscsi_data_001/lun_001_clone" -InitiatorGroup igroup_001 -VserverContext vserver3 -ErrorAction Stop
Mapped LUN clone "/vol/iscsi_data_001/lun_001_clone" to igroup "igroup_001" on vserver "vserver3"

CLI result:

 

cluster1::> lun show
Vserver   Path                            State   Mapped   Type        Size
--------- ------------------------------- ------- -------- -------- --------
vserver3  /vol/iscsi_data_001/lun_001     online  mapped   windows   10.00GB
vserver3  /vol/iscsi_data_001/lun_001_clone online mapped  windows   10.00GB
vserver3  /vol/iscsi_data_001/lun_002     online  mapped   windows   10.00GB
vserver3  /vol/iscsi_data_001/lun_003     online  mapped   windows   10.00GB
4 entries were displayed.

cluster1::> lun mapping show
Vserver    Path                                      Igroup   LUN ID  Protocol
---------- ----------------------------------------  -------  ------  --------
vserver3   /vol/iscsi_data_001/lun_001               igroup_001    0  iscsi
vserver3   /vol/iscsi_data_001/lun_001_clone         igroup_001    3  iscsi
vserver3   /vol/iscsi_data_001/lun_002               igroup_001    1  iscsi
vserver3   /vol/iscsi_data_001/lun_003               igroup_001    2  iscsi
4 entries were displayed.

Source Code:

 

 

Param(
   [Parameter(Mandatory =$True, HelpMessage = "The cluster name or IP address")]
   [String]$Cluster,
   [Parameter(Mandatory = $True, HelpMessage = "The name of the vserver")]
   [String]$VserverName,
   [Parameter(Mandatory = $True, HelpMessage = "The name of volume where the source and destination files or LUNs reside")]
   [String]$VolumeName,
   [Parameter(Mandatory = $True, HelpMessage = "The relative path of the source file or source LUN inside the volume")]
   [String]$SourcePath,
   [Parameter(Mandatory = $False, HelpMessage = "The relative path of the destination file or destination LUN inside the volume. The destination must be in same volume as the source. If not specified, the destination is taken as the source appended with 'Clone'")]
   [String]$DestinationPath,
   [Parameter(Mandatory = $False, HelpMessage = "The token which was used to reserve split load for creation of file or LUN clones")]
   [String]$TokenUuid,
   [Parameter(Mandatory = $False, HelpMessage = "The snapshot name from which to clone the source file or LUN. If not specified, the contents of the active filesystem will be used")]
   [String]$Snapshot,
   [Parameter(Mandatory = $False, HelpMessage = "The space reservation setting of the destination clone.  By default space reservation is inherited from source")]
   [Bool]$SpaceReserved,
   [Parameter(Mandatory = $False, HelpMessage = "If specified, clone only the base file and ignore streams on source or destination")]
   [Bool]$IgnoreStreams,
   [Parameter(Mandatory = $False, HelpMessage = "If specified, clone even if (advisory/mandatory) byte_range locks or share_mode locks exist on the source or destination")]
   [Bool]$IgnoreLocks,
   [Parameter(Mandatory = $False, HelpMessage = "The quality of service policy group name to assign to the created flexclone file")]
   [String]$QosPolicyGroup,
   [Parameter(Mandatory = $False, HelpMessage = "If specified, clones will be autodeleted to reclaim space when the volume runs out of space")]
   [Bool]$EnableAutodelete,
   [Parameter(Mandatory = $False, HelpMessage = "Specifies whether the clone is being created for backup - that is source file will get periodically modified, but the clone file should not be modified. The default value is false")]
   [Bool]$IsBackup,
   [Parameter(Mandatory = $False, HelpMessage = "The destination volume name")]
   [String]$DestinationVolume,
   [Parameter(Mandatory = $False, HelpMessage = "The number of times to retry commands that return with errors that may succeed after a retry")]
   [Int]$ZapiRetryCount,
   [Parameter(Mandatory = $False, HelpMessage = "The igroup name to map the LUN clone to")]
   [String]$IgroupName,
   [Parameter(Mandatory = $True, HelpMessage = "The credentials to connect to the cluster")]
   [System.Management.Automation.PSCredential]$Credentials
)
#'------------------------------------------------------------------------------
#'Import the DataONTAP PSTK.
#'------------------------------------------------------------------------------
[String]$moduleName = "DataONTAP"
[String]$command    = "Import-Module -Name $moduleName" 
Try{
   Invoke-Expression -Command $command -ErrorAction Stop
   Write-Host "Executed Command`: $command"
   Write-Host "Imported module ""$moduleName"""
}Catch{
   Write-Warning -Message $("Failed Executed Command`: $command. Error " + $_.Exception.Message)
   Write-Warning "Failed importing module ""$moduleName"""
   Break;
}
#'------------------------------------------------------------------------------
#'Connect to the cluster.
#'------------------------------------------------------------------------------
[String]$command = "Connect-NcController -Name $Cluster -HTTPS -Credential `$credentials -ErrorAction Stop"
Try{
   Invoke-Expression -Command $command -ErrorAction Stop | Out-Null
   Write-Host "Executed Command`: $command"
   Write-Host "Connected to cluster ""$Cluster"""
}Catch{
   Write-Warning -Message $("Failed Executed Command`: $command. Error " + $_.Exception.Message)
   Write-Warning "Failed connecting to cluster ""$Cluster"""
   Break;
}
#'------------------------------------------------------------------------------
#'Remove the volume mount point from the source path to create the LUN's relative path.
#'------------------------------------------------------------------------------
If($SourcePath.StartsWith("/vol/$VolumeName/")){
   [String]$SourcePath = $SourcePath -Replace("/vol/$VolumeName/", "")
}
If($SourcePath.StartsWith("/$VolumeName/")){
   [String]$SourcePath = $SourcePath -Replace("/$VolumeName/", "")
}
#'------------------------------------------------------------------------------
#'Create the command to create the file or LUN clone.
#'------------------------------------------------------------------------------
[String]$command = "New-NcClone -Volume $VolumeName -SourcePath $SourcePath "
If($DestinationPath){
   [String]$command += "-DestinationPath $DestinationPath "
}
If($TokenUuid){
   [String]$command += "-TokenUuid $TokenUuid "
}
If($Snapshot){
   [String]$command += "-Snapshot $Snapshot "
}
If($SpaceReserved){
   [String]$command += $("-SpaceReserved `$" + $SpaceReserved + " ")
}
If($IgnoreStreams){
   [String]$command += "-IgnoreStreams "
}
If($IgnoreLocks){
   [String]$command += "-IgnoreLocks "
}
If($QosPolicyGroup){
   [String]$command += "-QosPolicyGroup $QosPolicyGroup "
}
If($EnableAutodelete){
   [String]$command += "-EnableAutodelete "
}
If($IsBackup){
   [String]$command += $("-IsBackup `$" + $IsBackup + " ")
}
If($DestinationVolume){
   [String]$command += "-DestinationVolume $DestinationVolume "
}
If($ZapiRetryCount){
   [String]$command += $("-ZapiRetryCount " + $ZapiRetryCount.ToString() + " ")
}
[String]$command += "-VserverContext $VserverName -ErrorAction Stop"
#'------------------------------------------------------------------------------
#'Invoke the command to create the file or LUN clone.
#'------------------------------------------------------------------------------
Try{
   Invoke-Expression -Command $command -ErrorAction Stop
   Write-Host "Executed Command`: $command"
   Write-Host "Created clone of ""/vol/$VolumeName/$SourcePath"" on vserver ""$VserverName"""
}Catch{
   Write-Warning -Message $("Failed Executing Command`: $command. Error " + $_.Exception.Message)
   Write-Warning -Message "Failed creating clone of ""/vol/$VolumeName/$SourcePath"" on vserver ""$VserverName""" 
   Break;
}
#'------------------------------------------------------------------------------
#'Map the LUN clone to the igroup.
#'------------------------------------------------------------------------------
If($IgroupName){
   [String]$command = "Add-NcLunMap -Path ""/vol/$DestinationVolume/$DestinationPath"" -InitiatorGroup $IgroupName -VserverContext $VserverName -ErrorAction Stop"
   Try{
      Invoke-Expression -Command $command -ErrorAction Stop | Out-Null
      Write-Host "Executed Command`: $command"
      Write-Host "Mapped LUN clone ""/vol/$DestinationVolume/$DestinationPath"" to igroup ""$IgroupName"" on vserver ""$VserverName"""
   }Catch{
      Write-Warning -Message $("Failed Executing Command`: $command. Error " + $_.Exception.Message)
      Write-Warning -Message "Failed mapping LUN clone ""/vol/$DestinationVolume/$DestinationPath"" to igroup ""$IgroupName""  on vserver ""$VserverName""" 
   }
}
#'------------------------------------------------------------------------------

Note: I highly recommend you consider using WFA as an orchestration application for process like this instead of a script as it enables centralised RBAC access, a REST API, logging, auditing etc (Also It's FREE)

 

/Matt

 

 

If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.

View solution in original post

5 REPLIES 5

mbeattie
4,544 Views

Hi,

 

An example of the syntax can be found here:

 

https://library.netapp.com/ecmdocs/ECMP1610211/html/GUID-125543E9-5765-4CD4-8975-4CF6832BB19C.html

 

Also see:

 

PS C:\> Get-Help New-NcClone

NAME
    New-NcClone

SYNOPSIS
    Clone a file or LUN.


SYNTAX
    New-NcClone [-Volume] <String> [-SourcePath] <String> [[-DestinationPath] <String>] [[-TokenUuid] <String>] [-Snapshot <String>] [-SpaceReserved <Boolean>] [-IgnoreStreams] [-IgnoreLocks] [-QosPolicyGroup <String>] [-EnableAutodelete]
    [-IsBackup <Boolean>] [-DestinationVolume <String>] [-VserverContext <String>] [-Controller <NcController[]>] [-ZapiRetryCount <Int32>] [<CommonParameters>]


DESCRIPTION
    Clone a file or LUN.  This is a constant-time, synchronous operation.


RELATED LINKS
    Get-NcLun

REMARKS
    To see the examples, type: "get-help New-NcClone -examples".
    For more information, type: "get-help New-NcClone -detailed".
    For technical information, type: "get-help New-NcClone -full".
    For online help, type: "get-help New-NcClone -online"

/Matt

If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.

Sergey_Osipov
4,521 Views

You can also check the syntax here

https://docs.netapp.com/ontap-9/topic/com.netapp.doc.dot-cm-cmpr-940/volume__file__clone__create.html?resultof=%22%63%6c%6f%6e%65%22%20%22%63%72%65%61...

 

Please bear in mind that it will restore the lun within the cluster

As far as I understood from your message you want to restore this lun from a snapmirror destiantion.

Assuming that you want this lun to be restored to original production cluster then this command is not an option here

So I would recommend you to have a look here

https://docs.netapp.com/ontap-9/topic/com.netapp.doc.dot-cm-cmpr-940/snapmirror__restore.html?resultof=%22%73%6e%61%70%6d%69%72%72%6f%72%22%20%22%72%6...

snapmirror restore ommand restores the entire contents of a Snapshot copy or one or more files, LUNs or NVMe namespaces of a Snapshot copy from one volume to another volume.

 

mrembas
4,500 Views

Thank you for all sugestions but all this methods going to override original volume from snapshot

 

My goal is - as it was when you clone LUNs, just mount volume from selected snapshot and expose client as additional LUN, next to the production luns.

Final effect should be :

- have oryginal LUNs and non-disruptive 

- have additional LUN taken from snapshot

 

Any ideas ?

For NAS storage you can see hidden dircetory ".snapshot" and you can go there to recover you r files

But when you use SAN you can only restore whole volume to the oryginal volume or to mirrored/ paired cluster

Thanks

mbeattie
4,489 Views

Hi,

 

I tested the process in my lab, create a few LUNs, mapped them, formatted and mounted. Copied some data to a LUN, created a snapshot, deleted the data, then ran the following script which enabled me to restore the deleted files from the cloned LUN on the host.

 

The powershell code below will enable you to clone a source LUN and map it to an igroup based on a source snapshot name. I would recommend that you consider using WFA for this process instead of script but it's just an example for you. EG:

 

PS C:\Scripts\PowerShell\Projects\CreateLunClone> $credentials = Get-Credential -Credential admin
PS C:\Scripts\PowerShell\Projects\CreateLunClone> .\CreateLunClone.ps1 -Cluster cluster1.testlab.local -VserverName vserver3 -VolumeName iscsi_data_001 -SourcePath "/vol/iscsi_data_001/lun_001" -DestinationVolume iscsi_data_001 -Destination
Path "lun_001_clone" -Snapshot clonetest -SpaceReserved $false -IgroupName igroup_001 -Credentials $credentials
Executed Command: Connect-NcController -Name cluster1.testlab.local -HTTPS -Credential $credentials -ErrorAction Stop
Imported module "DataONTAP"
Executed Command: New-NcClone -Volume iscsi_data_001 -SourcePath lun_001 -DestinationPath lun_001_clone -Snapshot clonetest -DestinationVolume iscsi_data_001 -VserverContext vserver3 -ErrorAction Stop
Created clone of "/vol/iscsi_data_001/lun_001" on vserver "vserver3"
Executed Command: Add-NcLunMap -Path "/vol/iscsi_data_001/lun_001_clone" -InitiatorGroup igroup_001 -VserverContext vserver3 -ErrorAction Stop
Mapped LUN clone "/vol/iscsi_data_001/lun_001_clone" to igroup "igroup_001" on vserver "vserver3"

CLI result:

 

cluster1::> lun show
Vserver   Path                            State   Mapped   Type        Size
--------- ------------------------------- ------- -------- -------- --------
vserver3  /vol/iscsi_data_001/lun_001     online  mapped   windows   10.00GB
vserver3  /vol/iscsi_data_001/lun_001_clone online mapped  windows   10.00GB
vserver3  /vol/iscsi_data_001/lun_002     online  mapped   windows   10.00GB
vserver3  /vol/iscsi_data_001/lun_003     online  mapped   windows   10.00GB
4 entries were displayed.

cluster1::> lun mapping show
Vserver    Path                                      Igroup   LUN ID  Protocol
---------- ----------------------------------------  -------  ------  --------
vserver3   /vol/iscsi_data_001/lun_001               igroup_001    0  iscsi
vserver3   /vol/iscsi_data_001/lun_001_clone         igroup_001    3  iscsi
vserver3   /vol/iscsi_data_001/lun_002               igroup_001    1  iscsi
vserver3   /vol/iscsi_data_001/lun_003               igroup_001    2  iscsi
4 entries were displayed.

Source Code:

 

 

Param(
   [Parameter(Mandatory =$True, HelpMessage = "The cluster name or IP address")]
   [String]$Cluster,
   [Parameter(Mandatory = $True, HelpMessage = "The name of the vserver")]
   [String]$VserverName,
   [Parameter(Mandatory = $True, HelpMessage = "The name of volume where the source and destination files or LUNs reside")]
   [String]$VolumeName,
   [Parameter(Mandatory = $True, HelpMessage = "The relative path of the source file or source LUN inside the volume")]
   [String]$SourcePath,
   [Parameter(Mandatory = $False, HelpMessage = "The relative path of the destination file or destination LUN inside the volume. The destination must be in same volume as the source. If not specified, the destination is taken as the source appended with 'Clone'")]
   [String]$DestinationPath,
   [Parameter(Mandatory = $False, HelpMessage = "The token which was used to reserve split load for creation of file or LUN clones")]
   [String]$TokenUuid,
   [Parameter(Mandatory = $False, HelpMessage = "The snapshot name from which to clone the source file or LUN. If not specified, the contents of the active filesystem will be used")]
   [String]$Snapshot,
   [Parameter(Mandatory = $False, HelpMessage = "The space reservation setting of the destination clone.  By default space reservation is inherited from source")]
   [Bool]$SpaceReserved,
   [Parameter(Mandatory = $False, HelpMessage = "If specified, clone only the base file and ignore streams on source or destination")]
   [Bool]$IgnoreStreams,
   [Parameter(Mandatory = $False, HelpMessage = "If specified, clone even if (advisory/mandatory) byte_range locks or share_mode locks exist on the source or destination")]
   [Bool]$IgnoreLocks,
   [Parameter(Mandatory = $False, HelpMessage = "The quality of service policy group name to assign to the created flexclone file")]
   [String]$QosPolicyGroup,
   [Parameter(Mandatory = $False, HelpMessage = "If specified, clones will be autodeleted to reclaim space when the volume runs out of space")]
   [Bool]$EnableAutodelete,
   [Parameter(Mandatory = $False, HelpMessage = "Specifies whether the clone is being created for backup - that is source file will get periodically modified, but the clone file should not be modified. The default value is false")]
   [Bool]$IsBackup,
   [Parameter(Mandatory = $False, HelpMessage = "The destination volume name")]
   [String]$DestinationVolume,
   [Parameter(Mandatory = $False, HelpMessage = "The number of times to retry commands that return with errors that may succeed after a retry")]
   [Int]$ZapiRetryCount,
   [Parameter(Mandatory = $False, HelpMessage = "The igroup name to map the LUN clone to")]
   [String]$IgroupName,
   [Parameter(Mandatory = $True, HelpMessage = "The credentials to connect to the cluster")]
   [System.Management.Automation.PSCredential]$Credentials
)
#'------------------------------------------------------------------------------
#'Import the DataONTAP PSTK.
#'------------------------------------------------------------------------------
[String]$moduleName = "DataONTAP"
[String]$command    = "Import-Module -Name $moduleName" 
Try{
   Invoke-Expression -Command $command -ErrorAction Stop
   Write-Host "Executed Command`: $command"
   Write-Host "Imported module ""$moduleName"""
}Catch{
   Write-Warning -Message $("Failed Executed Command`: $command. Error " + $_.Exception.Message)
   Write-Warning "Failed importing module ""$moduleName"""
   Break;
}
#'------------------------------------------------------------------------------
#'Connect to the cluster.
#'------------------------------------------------------------------------------
[String]$command = "Connect-NcController -Name $Cluster -HTTPS -Credential `$credentials -ErrorAction Stop"
Try{
   Invoke-Expression -Command $command -ErrorAction Stop | Out-Null
   Write-Host "Executed Command`: $command"
   Write-Host "Connected to cluster ""$Cluster"""
}Catch{
   Write-Warning -Message $("Failed Executed Command`: $command. Error " + $_.Exception.Message)
   Write-Warning "Failed connecting to cluster ""$Cluster"""
   Break;
}
#'------------------------------------------------------------------------------
#'Remove the volume mount point from the source path to create the LUN's relative path.
#'------------------------------------------------------------------------------
If($SourcePath.StartsWith("/vol/$VolumeName/")){
   [String]$SourcePath = $SourcePath -Replace("/vol/$VolumeName/", "")
}
If($SourcePath.StartsWith("/$VolumeName/")){
   [String]$SourcePath = $SourcePath -Replace("/$VolumeName/", "")
}
#'------------------------------------------------------------------------------
#'Create the command to create the file or LUN clone.
#'------------------------------------------------------------------------------
[String]$command = "New-NcClone -Volume $VolumeName -SourcePath $SourcePath "
If($DestinationPath){
   [String]$command += "-DestinationPath $DestinationPath "
}
If($TokenUuid){
   [String]$command += "-TokenUuid $TokenUuid "
}
If($Snapshot){
   [String]$command += "-Snapshot $Snapshot "
}
If($SpaceReserved){
   [String]$command += $("-SpaceReserved `$" + $SpaceReserved + " ")
}
If($IgnoreStreams){
   [String]$command += "-IgnoreStreams "
}
If($IgnoreLocks){
   [String]$command += "-IgnoreLocks "
}
If($QosPolicyGroup){
   [String]$command += "-QosPolicyGroup $QosPolicyGroup "
}
If($EnableAutodelete){
   [String]$command += "-EnableAutodelete "
}
If($IsBackup){
   [String]$command += $("-IsBackup `$" + $IsBackup + " ")
}
If($DestinationVolume){
   [String]$command += "-DestinationVolume $DestinationVolume "
}
If($ZapiRetryCount){
   [String]$command += $("-ZapiRetryCount " + $ZapiRetryCount.ToString() + " ")
}
[String]$command += "-VserverContext $VserverName -ErrorAction Stop"
#'------------------------------------------------------------------------------
#'Invoke the command to create the file or LUN clone.
#'------------------------------------------------------------------------------
Try{
   Invoke-Expression -Command $command -ErrorAction Stop
   Write-Host "Executed Command`: $command"
   Write-Host "Created clone of ""/vol/$VolumeName/$SourcePath"" on vserver ""$VserverName"""
}Catch{
   Write-Warning -Message $("Failed Executing Command`: $command. Error " + $_.Exception.Message)
   Write-Warning -Message "Failed creating clone of ""/vol/$VolumeName/$SourcePath"" on vserver ""$VserverName""" 
   Break;
}
#'------------------------------------------------------------------------------
#'Map the LUN clone to the igroup.
#'------------------------------------------------------------------------------
If($IgroupName){
   [String]$command = "Add-NcLunMap -Path ""/vol/$DestinationVolume/$DestinationPath"" -InitiatorGroup $IgroupName -VserverContext $VserverName -ErrorAction Stop"
   Try{
      Invoke-Expression -Command $command -ErrorAction Stop | Out-Null
      Write-Host "Executed Command`: $command"
      Write-Host "Mapped LUN clone ""/vol/$DestinationVolume/$DestinationPath"" to igroup ""$IgroupName"" on vserver ""$VserverName"""
   }Catch{
      Write-Warning -Message $("Failed Executing Command`: $command. Error " + $_.Exception.Message)
      Write-Warning -Message "Failed mapping LUN clone ""/vol/$DestinationVolume/$DestinationPath"" to igroup ""$IgroupName""  on vserver ""$VserverName""" 
   }
}
#'------------------------------------------------------------------------------

Note: I highly recommend you consider using WFA as an orchestration application for process like this instead of a script as it enables centralised RBAC access, a REST API, logging, auditing etc (Also It's FREE)

 

/Matt

 

 

If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.

mrembas
4,458 Views

Thank you Matt

 

The PS-Module is really cool. In the details how to calculate the needed space on volume.

First warn after executed was Error Clone operation failed to start: Volume is full or Volume crossed autodelete threshold..

I have 10% snapshot reservation on that volume. I really appreciate any approach in calculation.

 

Thank you 

Public