
UNSOLVED
DB
DELL-Bill Gr
50 Posts
0
6422
November 21st, 2011 11:00
Powershell - Seperate push2tape into two scripts
This post has been copied from the former Compellent User Forum and placed here for your reference. This code is made available AS IS, without warranty of any kind. The entire risk of the use or the results from the use of this code remains with the user.
Seperate push2tape into two scripts – Originally posted By quentin, 18 Mar 2011
quentin - I was tasked with using this excellent script to assist in our backup process. I would like to seperate this into two scripts for use with BackupExec 2010 R2's pre and post job setting. I am quite new to powershell and cannot seem to figure out how to get the information necessary from the pre script to unmount and delete the replay view that my pre script creates. Would one of you fine folks mind giving me a quick example of how i could split the default push2tape script into two?. All assistance is very much appreciated.
CIS - We tasked a contractor to do this, and he did it by naming all of the variables (server name, volume name, mount path) with an "X" in front of them and exporting these variables with this command: "Get-Variable X* |Export-Clixml variables.xml" where "variables.xml" is the filename to store the variables. The second script - which dismounted the volumes - included a command "Import-Clixml .\variables.xml | %{ Set-Variable $_.Name $_.Value }" which read the exported variables from the first script.
Compellent Co-pilot support was very helpful with this as well; I can send you an example of a modified push2tape script that I'm currently testing to do exactly what you are attempting to do if you'd like, or you can contact them directly for assistance. Keep in mind I'm not knowledgeable of powershell either; that's why we hired a contractor to assist :)
Hope that helps.
quentin - Wonderful!, would you mind sharing your scripts with me?. That would be great.
CIS - I don't see any way to attach anything, so here they are; let me know if you can't read them. Also, you'll have to modify some of the variables for your environment, as well as the IP address of the storage center (which I've changed to xx.xx.xx.xx to protect the innocent :)), and you may have to adjust the $pass line depending upon how/where you've stored the Storage Center password. Finally, keep in mind that I'm still testing these; they don't work consistently in my environment yet - sometimes the volume drive letter shows up in Windows, sometimes not - but they work for Compellent so there's hope that they may work for you.
BackupJob-Mount.ps1:
# Copyright (c) 2008 Compellent Technologies. All rights reserved.
#
# THIS CODE IS MADE AVAILABLE AS IS, WITHOUT WARRANTY OF ANY KIND. THE ENTIRE RISK
# OF THE USE OR THE RESULTS FROM THE USE OF THIS CODE REMAINS WITH THE USER.
#
#
# DESC: PowerShell script to expose replay to a backup server for offloading backup to tape.
#
param
(
[string] $Xservername = "Server1", # Server being used for all back-ups
[string] $Xvolumename1 = "Volume1", # Volume1 for Back-ups
[string] $Xvolumename2 = "Volume2", # Volume2 for Back-ups
[string] $Xvolumename3 = "Volume3", # Volume3 for Back-ups
[string] $Xaccesspath1 = "S:" , # Volume1 Access path
[string] $Xaccesspath2 = "T:" , # Volume2 Access path
[string] $Xaccesspath3 = "U:" , # Volume3 Access path
[string] $Xnewreplayname1= "Volume1_Backup" , # Name to call the replay view volume
[string] $Xnewreplayname2= "Volume2_Backup" , # Name to call the replay view volume
[string] $Xnewreplayname3= "Volume3_Backup" # Name to call the replay view volume
)
Add-PSSnapin Compellent.StorageCenter.Scripting
#How to handle errors
#"SilentlyContinue": do not print, continue
#"Continue": Print, continue (this is the default)
#"Stop": Halt the command or script
#"Inquire": Ask the user what to do
$ErrorActionPreference = "Continue"
# Storage Center User to run script
$user = "Admin"
# Storage Center Password (stored in clear text for this script)
$pass = ConvertTo-SecureString (Get-Content C:\password.txt)
# The following line can be used as an alternate way to get the password without hard coding it
#$pass = Read-Host -AsSecureString -Prompt "Please provide the Storage Center password for $user"
# Storage Center Host Name or IP Address
$Xschost = "xx.xx.xx.xx"
# Instantiate Connection to Storage Center
# Uncomment last section to have this Storage Center connection saved as the default connection to use
# for all command.
$connection = Get-SCConnection -HostName $Xschost -User $user -Password $pass -Save $Xschost -Default
# Get Server Info
$Xscserver = Get-SCServer -Name $Xservername
if ($Xscserver -eq $null)
{
Write-Host "Unable to find server $Xservername on Storage Center $Xschost!" -ForegroundColor Red
break;
}
Write-Host "This script will back up volumes $Xvolumename1 ," -ForegroundColor Magenta
Write-Host " $Xvolumename2 , and $Xvolumename3 on to Back up Volumes" -ForegroundColor Magenta
Write-Host " $Xnewreplayname1 , $Xnewreplayname2 , and $Xnewreplayname3" -ForegroundColor Magenta
Start-Sleep 5
##################################################################################
# Get last replay from volume1
Write-Host "Checking for available replays for $Xvolumename1 ..." -ForegroundColor Gray
$Xreplays1 = Get-SCReplay -SourceVolumeName $Xvolumename1 | where{$_.State -eq "Frozen"}
if ($Xreplays1 -eq $null -or $Xreplays1.Count -eq 0)
{
Write-Host "No frozen replays were found for volume $Xvolumename1 !" -ForegroundColor Red
break;
}
# We want only the most recent replay
$Xlatestreplay1 = $Xreplays1[-1]
# Create View
# $newreplayname1 = "$volumename1 View " + $latestreplay1.Index
Write-Host "Creating view from replay..." -ForegroundColor Gray
$Xreplayview1 = New-SCVolume -SourceReplay $Xlatestreplay1 -Name $Xnewreplayname1
#################################################################################
# Get last replay from volume2
Write-Host "Checking for available replays for $Xvolumename2 ..." -ForegroundColor Gray
$Xreplays2 = Get-SCReplay -SourceVolumeName $Xvolumename2 | where{$_.State -eq "Frozen"}
if ($Xreplays2 -eq $null -or $Xreplays2.Count -eq 0)
{
Write-Host "No frozen replays were found for volume $Xvolumename2 !" -ForegroundColor Red
break;
}
# We want only the most recent replay
$Xlatestreplay2 = $Xreplays2[-1]
# Create View
# $Xnewreplayname2 = "$Xvolumename2 View " + $Xlatestreplay2.Index
Write-Host "Creating view from replay..." -ForegroundColor Gray
$Xreplayview2 = New-SCVolume -SourceReplay $Xlatestreplay2 -Name $Xnewreplayname2
#################################################################################
# Get last replay from volume3
Write-Host "Checking for available replays for $Xvolumename3 ..." -ForegroundColor Gray
$Xreplays3 = Get-SCReplay -SourceVolumeName $Xvolumename3 | where{$_.State -eq "Frozen"}
if ($Xreplays3 -eq $null -or $Xreplays3.Count -eq 0)
{
Write-Host "No frozen replays were found for volume $Xvolumename3 !" -ForegroundColor Red
break;
}
# We want only the most recent replay
$Xlatestreplay3 = $Xreplays3[-1]
# Create View
# $Xnewreplayname3 = "$Xvolumename3 View " + $Xlatestreplay3.Index
Write-Host "Creating view from replay..." -ForegroundColor Gray
$Xreplayview3 = New-SCVolume -SourceReplay $Xlatestreplay3 -Name $Xnewreplayname3
#################################################################################
# Map View to server
Write-Host "Mapping $Xnewreplayname1 view to server..." -ForegroundColor Gray
New-SCVolumeMap -VolumeIndex $Xreplayview1.Index -ServerIndex $Xscserver.Index -SinglePath
Write-Host "Mapping $Xnewreplayname2 view to server..." -ForegroundColor Gray
New-SCVolumeMap -VolumeIndex $Xreplayview2.Index -ServerIndex $Xscserver.Index -SinglePath
Write-Host "Mapping $Xnewreplayname3 view to server..." -ForegroundColor Gray
New-SCVolumeMap -VolumeIndex $Xreplayview3.Index -ServerIndex $Xscserver.Index -SinglePath
# Rescan Server
Write-Host "Rescanning $Xservername for new replay volume..." -ForegroundColor Gray
Rescan-DiskDevice -Server $Xservername -RescanDelay 5
Write-Output -ForegroundColor Green "Bringing Disk Online..."
Set-DiskDevice -SerialNumber $Xscvolume1.SerialNumber -Online
Set-DiskDevice -SerialNumber $Xscvolume1.SerialNumber -ReadOnly:$false
Set-DiskDevice -SerialNumber $Xscvolume2.SerialNumber -Online
Set-DiskDevice -SerialNumber $Xscvolume2.SerialNumber -ReadOnly:$false
Set-DiskDevice -SerialNumber $Xscvolume3.SerialNumber -Online
Set-DiskDevice -SerialNumber $Xscvolume3.SerialNumber -ReadOnly:$false
# Add Access Path
Write-Host -ForegroundColor Green "Adding access path for new replay $Xvolumename1 ..."
Add-VolumeAccessPath -SerialNumber $Xreplayview1.SerialNumber -Server $Xservername -AccessPath $Xaccesspath1
Write-Host -ForegroundColor Green "Adding access path for new replay $Xvolumename2 ..."
Add-VolumeAccessPath -SerialNumber $Xreplayview2.SerialNumber -Server $Xservername -AccessPath $Xaccesspath2
Write-Host -ForegroundColor Green "Adding access path for new replay $Xvolumename3 ..."
Add-VolumeAccessPath -SerialNumber $Xreplayview3.SerialNumber -Server $Xservername -AccessPath $Xaccesspath3
Write-Host "Rescanning server for new replay volume..." -ForegroundColor Gray
Rescan-DiskDevice -Server $Xservername -RescanDelay 5
# Kick off tape backup process here
Write-Host "Backup up volume to tape..." -ForegroundColor Gray
Write-Host "3 Back-up volumes are mapped up" -ForegroundColor Gray
## Export Variables
write-host $Xservername
write-host $Xschost
write-host $Xscserver
write-host $Xaccesspath1
write-host $Xaccesspath2
write-host $Xaccesspath3
write-host $Xvolumename1
write-host $Xvolumename2
write-host $Xvolumename3
Get-Variable X* |Export-Clixml vars_BackupJob1.xml
And here's the other script...
BackupJob-Dismount.ps1
# Copyright (c) 2008 Compellent Technologies. All rights reserved.
#
# THIS CODE IS MADE AVAILABLE AS IS, WITHOUT WARRANTY OF ANY KIND. THE ENTIRE RISK
# OF THE USE OR THE RESULTS FROM THE USE OF THIS CODE REMAINS WITH THE USER.
#
#
# DESC: PowerShell script to expose replay to a backup server for offloading backup to tape.
#
Add-PSSnapin Compellent.StorageCenter.Scripting
Import-Clixml .\vars_BackupJob1.xml | %{ Set-Variable $_.Name $_.Value }
#Import-Csv c:\vars.csv | Set-Variable
#write-host $Xservername
#write-host $Xschost
#Get-Variable Xservername
#break
# Get rid of the view volume
Write-Host "Removing first backup volume..." -ForegroundColor Magenta
Remove-SCVolume -Index $Xreplayview1.Index -SkipRecycleBin -Confirm:$false
# Clean up on the server
Rescan-DiskDevice -Server $Xservername -RescanDelay 5
# Get rid of the view volume
Write-Host "Removing second backup volume..." -ForegroundColor Magenta
Remove-SCVolume -Index $Xreplayview2.Index -SkipRecycleBin -Confirm:$false
# Clean up on the server
Rescan-DiskDevice -Server $Xservername -RescanDelay 5
# Get rid of the view volume
Write-Host "Removing third backup volume..." -ForegroundColor Magenta
Remove-SCVolume -Index $Xreplayview3.Index -SkipRecycleBin -Confirm:$false
# Clean up on the server
Rescan-DiskDevice -Server $Xservername -RescanDelay 5
quentin - This is exactly what I needed. Thank you so much!. Great example.
quentin - This was done in Command Set 5?. 6 doesn't seem to like the .Index and -Index. Any idea on how to go about the mapping and removing in 6?
bmiddauch - All of the changes from Storage Center Command Set 5.0 to 6.0 are documented in the Storage Center Command Set 6.0 for Windows PowerShell User Guide available from the Knowledge Base.
The changes in the actual scripts are:
5.0 used this command for the Snap-in: Add-PSSnapin Compellent.StorageCenter.Scripting
6.0 uses this command for the Snap-in: Add-PSSnapin Compellent.StorageCenter.PSSnapin
In sample scripts 5.0 used:
$replayview = New-SCVolume -SourceReplay $latestreplay -Name $newreplayname
New-SCVolumeMap -VolumeIndex $replayview.Index -ServerIndex $scserver.Index -SinglePath
Remove-SCVolume -Index $replayview.Index -SkipRecycleBin -Confirm:$false
In sample scripts 6.0 used:
$replayview = New-SCVolume -SourceSCReplay $latestreplay -Name $newreplayname
New-SCVolumeMap -SCVolume $replayview -SCServer $scserver -SinglePath
Remove-SCVolume -SCVolume $replayview -SkipRecycleBin -Confirm:$false
In 5.0 sample scripts were installed here by default:
C:\Program Files\Compellent Technologies\Storage Center Command Set\Script Samples
In 6.0 sample scripts were installed here by default:
C:\Program Files\Compellent Technologies\Storage Center PowerShell Command Set\Script Samples
Responses (0)
Solutions (0)
