Prerequisites
1) SMBR is installed
2) ONTAP PowerShell Toolkit is installed
3) The server has iSCSI interfaces
4) An initiator group for the server exists on the
relevant SVM
5) iSCSI is setup on the SMBR server
6) Credentials to connect to the SVM
Below is an example of the required setup (for 3,4,5). Here
we configure MPIO but only have one iSCSI IP on the server (.75) and one iSCSI
LIF on the cluster (.131) This is a one-time setup:
get-windowsfeature -name 'Multipath-IO'
add-windowsfeature -name 'Multipath-IO'
get-netipaddress | where-object
{$_.AddressFamily -eq "IPv4"}
set-service -name MSiSCSI -StartupType
Automatic
Start-service -name MSiSCSI
hostname
igroup create -vserver svm1 -igroup
iqn.1991-05.com.microsoft:smbr.demo.corp.com -protocol iscsi -ostype windows
-initiator iqn.1991-05.com.microsoft:smbr.demo.corp.com
New-IscsiTargetPortal
-InitiatorPortalAddress 192.168.0.75 -TargetPortalAddress 192.168.0.131
get-iscsitarget | connect-iscsitarget
-Ispersistent $True -IsMultipathEnabled $True -InitiatorPortalAddress
192.168.0.75 -TargetPortalAddress 192.168.0.131
Get-IscsiConnection
new-msdsmsupportedHw -VendorId NETAPP
-ProductId "LUN C-Mode"
Update-MPIOClaimedHW -Confirm:$false
restart-computer
Running from a Batch File
Image: FlexClone_DB_SnapShot_to_Server.BAT
You’ll need to put a batch file on the desktop, for the
exchange administrator to run the tool. The batch file - which we’ll call FlexClone_DB_SnapShot_to_Server.bat
- has this content:
PowerShell.EXE
C:\Scripts\FlexClone_DB_SnapShot_to_Server.PS1 -SVMName {SVM Name} -HostIGrp {Host Initiator
Group Name} -SVMMgmtLIF {SVM Management LIF} -SVMUser vsadmin
PowerShell Script
This the script:
Param(
[String]$SVMName,
[String]$HostIGrp,
[String]$SVMMgmtLIF,
[String]$SVMUser
)
Function Wr{
Param([String]$Echo,[String]$Ink = "WHITE")
If($Echo){Write-Host $Echo -ForegroundColor $Ink -NoNewLine}
Else{Write-Host}
}
####################
## INITIALIZATION ##
####################
[Void](Import-Module DataONTAP)
If(!(Get-Module DataONTAP)){Wr
"Import-Module DataONTAP failed" RED;Wr;PAUSE;EXIT}
Wr;Wr "+++++ Mount DB Snapshot to
the SMBR Server +++++" MAGENTA;Wr;Wr
Wr "SVM Name : " CYAN;If($SVMName){Wr $SVMName;Wr}else{$SVMName
= Read-Host}
Wr "Host IGroup : " CYAN;If($HostIGrp){Wr
$HostIGrp;Wr}else{$HostIGrp = Read-Host}
Wr "SVM Mgmt. LIF : "
CYAN;If($SVMMgmtLIF){Wr $SVMMgmtLIF;Wr}else{$SVMMgmtLIF = Read-Host}
Wr "SVM Username : " CYAN;If($SVMUser){Wr $SVMUser;Wr}else{$SVMuser
= Read-Host}
Wr "SVM Password : " CYAN;$SecurePW = Read-Host
-AsSecureString
Wr "Recovery Drive: " CYAN;Wr
"R";Wr
$Creds = New-Object
System.Management.Automation.PsCredential($SVMUser,$SecurePW)
## CHECKING SVM CONNECTION ##
[Void](Connect-NcController -Name
$SVMMgmtLIF -Credential $Creds -Vserver $SVMName -ErrorAction SilentlyContinue)
If(!$Global:CurrentNcController){
Wr
"Connect to $SVMName failed!" RED;Wr;PAUSE;EXIT
};Wr
## CHECKING IGROUP EXISTENCE ##
If(!(Get-NcIgroup | Where{$_.Name -eq
$HostIGrp})){Wr "Could not find initiator group $HostIGrp"
RED;Wr;PAUSE;EXIT}
## CHECKING ISCSI CONNECTIONS ##
$ConnectedCount = 0
[System.Object]$HostIscsi =
Get-iSCSIConnection
ForEach($SANLIF in Get-NcISCSIInterface){
$HostIscsi | Foreach{
If($SANLIF.IpAddress -eq $_.TargetAddress){
Wr (($_.InitiatorAddress) + " is connected to " +
($SANLIF.IpAddress)) GREEN;Wr
$ConnectedCount++
}
}
}
If($ConnectedCount -ge 1){
Wr "At least one iSCSI connection detected!" GREEN; Wr;
Wr "Note: Currently, we only check for at least one connection.
This does not guarantee the LUN mapping will work!" CYAN;Wr
}Else{
Wr "No iSCSI connections detected!" RED;Wr;PAUSE;EXIT
};Wr
##########################################################
## CUSTOMER INPUTS - customization will
be needed here! ##
##########################################################
[System.Array]$DBs =
"1","2","3","4","5"
$GoodInput = $FALSE
While(!$GoodInput){
Wr "Which database do you want to restore from (1-5)? "
CYAN;[String]$Database = Read-Host
$DBs | Foreach{If($Database -eq $_){$GoodInput = $TRUE}}
}
$Attrs = Get-NcVol -Template
$Attrs.VolumeSnapshotAttributes = @{}
Wr;Wr "Searching for
volumes..." MAGENTA;Wr;Wr
[System.Object]$Vols = Get-NcVol
-Attributes $Attrs | where{$_.name.contains("DB" +
"$Database")}
Wr "Volume Name (snapshot
count)" CYAN;Wr
$Vols | Foreach{
Wr ($_.Name + " (" + $_.VolumeSnapshotAttributes.SnapshotCount
+ ")");Wr
};Wr
$GoodInput = $FALSE
While(!$GoodInput){
Wr "Which volume do you want to restore from? "
CYAN;[String]$RestoVol = Read-Host
$Vols | Foreach{
If($RestoVol -eq $_.Name){$GoodInput = $TRUE}
}
}
$Attrs = Get-NcSnapshot -Template
$Attrs.AccessTime = ""
Wr;Wr "Searching for
snapshots..." MAGENTA;Wr;Wr
[System.Objects]$Snaps = Get-NcSnapshot
-Volume $RestoVol -Attributes $Attrs
Wr "Snapshot name' created @
MM/DD/YYYY HH:MM:SS AM/PM" CYAN;Wr
$Snaps | Foreach{
Wr ($_.Name) YELLOW;Wr " @ " CYAN;Wr ($_.Created);Wr
};Wr
$GoodInput = $FALSE
While(!$GoodInput){
Wr "Which " CYAN; Wr "snapshot name " YELLOW;Wr
" do you want to restore from? " CYAN
[String]$RestoSnap = Read-Host
$Snaps | Foreach{
If($RestoSnap -eq $_.Name){$GoodInput = $TRUE}
}
};Wr
###########
## CLONE ##
###########
$CloneVolName = ("$RestoVol" +
"_CLONE")
Wr "Creating clone volume: "
MAGENTA; Wr $CloneVolName YELLOW;Wr
Wr "...from snapshot: "
MAGENTA; Wr $RestoSnap YELLOW;Wr
Wr "...of volume: " MAGENTA; Wr
$RestoVol YELLOW;Wr
[Void](New-NcVolClone -CloneVolume
$CloneVolName -Parentvolume $RestoVol -ParentSnapshot $RestoSnap -VolumeType
RW)
## FIRST CHECK TO SEE IF ANYTHING
MAPPINGS EXIST ##
$Query = Get-NcLunMap -Template
$Query.InitiatorGroup = $HostIGrp
[System.Object]$LunMaps = Get-NcLunMap
-Query $Query
$LUNID = 1
If($LunMaps.count -ne 0){
Wr "There are already LUN mappings to this server. These may need
tidy up. Check with the Storage Team." YELLOW;Wr
$FoundFreeLUNID = $FALSE
While(!$FoundFreeLUNID){
$LunMaps | Foreach{
If($_.LunID -ne $LUNID){$FoundFreeLUNID = $TRUE}
Else{$LUNID++}
}
}
}
## MAP THE LUN (assuming one LUN per
volume) ##
$GetLUN = Get-NcLun -Volume $CloneVolName
$LUNPath = $GetLUN.Path
$LUNSerial = $GetLUN.SerialNumber
[Void](Add-NcLunMap -Path $LUNPath
-InitiatorGroup $HostIGrp -Id $LUNID)
## WINDOWS CONFIGURATION (assuming one
LUN per volume) ##
Update-HostStorageCache
[System.Object]$Disk = Get-Disk |
Where{$_.FriendlyName.contains("NETAPP")}
$Disk | Set-Disk -IsReadonly $FALSE
$Disk | Set-Disk -IsOffline $FALSE
$Disk | Get-Partition | Where{$_.Type -eq
"Basic"} | Set-Partition -NewDriveLetter R
Update-HostStorageCache
Explorer R:
## NOW DO THE RESTORE ##
Wr "LUN has been mounted as the R:
drive." GREEN;Wr
Wr "Use SMBR to restore your
data." CYAN;Wr;Wr
Wr "ONLY PRESS ENTER WHEN READY TO
START THE TIDY UP." RED;Wr;Wr
PAUSE
#############
## TIDY UP ##
#############
$Disk | Set-Disk -IsOffline $TRUE
[Void](Set-NcVol -Name $CloneVolName
-Offline)
[Void](Remove-NcVol -Name $CloneVolName
-Confirm:$False)
Update-HostStorageCache
Wr;Wr "Tidy up completed!"
GREEN;Wr;Wr
PAUSE
Comments
Post a Comment