Unsolved

This post is more than 5 years old

50 Posts

49410

November 21st, 2011 11:00

Powershell - Backing up scripted replay views with Netbackup

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.

Backing up scripted replay views with Netbackup – Originally posted By kalord, 06 Aug 2010

kalord - We are running Veritas Netbackup 6.5.3.1.

I recently wrote a PowerShell script to create a Replay View of a volume, map it to the backup server, and mount it to an empty NTFS folder so Veritas Netbackup can perform a local SAN backup of the data.

For some reason Netbackup is not performing incrementals properly.  There is something about the Replay View that causes Netbackup to perform a FULL backup every time.

The process is as follows:

1) The Netbackup Policy kicks off the Parent Backup job at 6pm

2) The Netbackup job kicks off a PRE-backup batch file which executes the PowerShell script

3) The Powershell script creates a new replay of the source volume, then creates a view of that replay.

4) The new view is mapped to the backup server, SCSI Rescans are performed until the view device is available, and it is mounted in a specified empty NTFS folder

5) The Netbackup job will then start backing up the specified folder to tape - HOWEVER, if the job is set as INCREMENTAL and a FULL backup has already been done on this volume, it will still do a FULL???

6) When the backup is complete, Netbackup will kick off a POST-backup batch file to run a different Powershell script which removes the mountpoint, removes the mapping of the replay view, and deletes the replay view on the Storage Center.

Does anyone have any idea why the Replay View is being treated as a new volume by Netbackup and a FULL backup is being done every time, when Netbackup should be going off the timestamps of the files and running an INCREMENTAL?

slasher - I believe NB sets one of the extended attributes on the file system to record that was backed up at a certain time.  So NB writes those attributes on the replay you have mounted.  When you replace that backed up replay with a new one, those attributes are lost so NB has no choice but to treat it like a "new" volume with a full backup.

kalord - Would you be referring to NB setting the archive bit?

That would make sense, as the Replay view is deleted after each backup and so the setting would be lost, but we have NB looking at the timestamp and not the archive bit.

We can't be the only ones utilizing scripted replay views for backup to tape.   How are others doing this successfully?

kalord - We continued testing incremental backups of Replay views today and found that regardless how a Replay view is created (enterprise mgr or powershell), or how the netbackup policy is set (archive bit or timestamp), Netbackup will always do a FULL backup of the view.

The only thing we can think of that may be changing between each backup attempt is the Windows disk signature - but even that shouldn't cause this type of behavior.

pongowongo - When you are using a readonly view for backup purposes, you need to use the modified date option in your backup software instead of using the archive bit. This is the only way to get any incremental or differential backup from a readonly replay.

Hope this helps.

quentin - Would you mind sharing your scripts. I am actually in the process of trying to figure out exactly how to do this, only difference is that we are utilizing backup exec 2010 R2.

kalord - I just migrated today to CommandSet 6.0 so forgive my lack of comments and shoddy formatting. 

It works, but I'm sure there are many places my logic could be improved upon.  Comments and suggestions are much appreciated!

FYI - These scripts are launched via a Netbackup schedule and use the

C:\Program Files\VERITAS\NetBackup\bin\bpstart_notify*.bat and C:\Program Files\VERITAS\NetBackup\bin\bpend_notify*.bat for those familiar with the process.

PRE-Backup Script

##########################################################################

# SCRIPT PARAMETERS                                                                          

# ONLY MODIFY THESE VARIABLES - DO NOT HARDCODE INTO SCRIPT!!!                                   

#                                                                                                 

# $SCHostName - The name of the Storage Center containing the source volume                      

# $SRCservername - The server the source volume is mapped to                                     

# $SRCvolumename - The name of the volume (as displayed in the Enterprise Manager)               

# $ReplayMinsTTL - The expiration time (in mins) of the new Replay

# $NBUSrvLun - the LUN number to use when mapping the Replay View to the NBU server            

# $NBUServername - the name of the NBU server mounting the new Replay View                      

# $DESCreplay - a short Description of the newly created Replay                                 

# $replayviewname - the name of the new View Volume created from the Replay               

# $NBUmountpoint - mount point on the NBU Server for new Replay View (must be NTFS empty folder) 

# $SCNBUFolder - the Volume Folder on the Storage Center to place the new View in              

###########################################################################

$SCHostName = "COMPELLENTSC1"

$SRCservername = "HOST_A"

$SRCvolumename = "HOST_A_VOLUME1"

$ReplayMinsTTL = "10"

$NBUSrvLun = "99"

$NBUservername = "HOST_BKP_SRV"

$DESCreplay = "HOST_A_VOLUME1 NBU Replay"

$replayviewname = "HOST_A_VOLUME1 NBU View"

$NBUmountpoint = "C:\BACKUPS\HOSTAVOL1"

$SCNBUFolder = "NBU"

## Create new logfile based on script name and current date/time

#

$dt = Get-Date -format "yyyyMMdd_hhmm"

$log = ($MyInvocation.MyCommand.Name).Replace(".ps1","_$dt.log")

$PSLogFile = "C:\BACKUPS\logs\PRE_" + $log

## Start transcript of all activities and set trap to stop transcript if a break is encountered

#

start-transcript $PSLogFile

trap { stop-transcript; break }

## Add the Compellent Powershell Commandlet SnapIn

Add-PSSnapin Compellent.StorageCenter.PSSnapin

##  How to handle errors

# "SilentlyContinue": On Error Do Not Print, Continue running to Exit

# "Continue": Print Error Message, Continue running to Exit (this is the default)

# "Stop": Halt and Break from Script

# "Inquire": On Error, Ask the user what to do

$ErrorActionPreference = "SilentlyContinue"

$pass = ConvertTo-SecureString (Get-Content c:\scripts\cmp_pwd.txt)

Get-SCConnection -HostName $SCHostName -User Admin -Password $pass -Save $SCHostName

Get-SCConnection -Name $SCHostName -Default

## Check existence of $NBUmountpoint - create if does not exist

#

if (!(Test-Path -path "$NBUmountpoint\"))

 {

  $logtime = Get-Date -format MMddyyyy-HH:mm:ss

  Write-Host $logtime  "  Directory $NBUmountpoint does not exist - creating $NBUmountpoint"

  New-Item "$NBUmountpoint\" -type directory

 }

 

## Create New Replay of Source Volume and place in $replay

#

$logtime = Get-Date -format MMddyyyy-HH:mm:ss

Write-Host $logtime  "  Creating new replay of source volume $SRCvolumename on $SCHostName" 

Get-SCVolume -Name $SRCvolumename | New-SCReplay -MinutesToLive $ReplayMinsTTL -Description $DESCreplay

sleep 30

## Get list of ALL Frozen Replays and place in array.  Sort array in descending order

## and select the most recent replay for View creation

#

$ALLReplays = Get-SCReplay -SourceVolumeName $SRCvolumename | where{$_.State -eq "Frozen"} | sort FreezeTime -Descending

if ($ALLReplays -eq $null)

 {

  # No available Frozen Replays found for Source Volume - exit script

  $logtime = Get-Date -format MMddyyyy-HH:mm:ss

  Write-Host $logtime "  No Frozen Replays are available for Replay View Creation - Exiting..."

  Break

 }

 

## If more than one replay then $ALLReplays is stored in array

## - set first array member (will be the most recent replay) as $replay for View creation

#

if ($ALLReplays -is [array])

 {

  $replay = $ALLReplays[0]

 }

else

 {

  # Only one replay found - use it for View creation

  $replay = $ALLReplays

 }

 

## Create the New Replay View which we will mount and use for backup

## and place in $replayview

#

$logtime = Get-Date -format MMddyyyy-HH:mm:ss

Write-Host $logtime  "  Creating new replay view of replay $DESCreplay on $SCHostName" 

$replayview = New-SCVolume -SourceReplay $replay -Name $replayviewname

## Move New View volume to NBU volume Folder

#

$logtime = Get-Date -format MMddyyyy-HH:mm:ss

Write-Host $logtime  "  Moving replay view of replay $DESCreplay on $SCHostName to Compellent Folder $SCNBUFolder" 

$NBUFolderObj = Get-SCVolumeFolder -Name $SCNBUFolder

Get-SCVolume -Name $replayviewname | Set-SCVolume -ParentSCVolumeFolder $NBUFolderObj

## Map New View volume LUN to Netbackup Server $NBUservername

#

$logtime = Get-Date -format MMddyyyy-HH:mm:ss

Write-Host $logtime  "  Mapping replay view of replay $DESCreplay on $SCHostName to server $NBUservername" 

$NBUServerObj = Get-SCServer -Name $NBUservername

$NBUVolMapObj = Get-SCVolume -Index $replayview.Index

New-SCVolumeMap -SCVolume $NBUVolMapObj -SCServer $NBUServerObj -LUN $NBUSrvLun -SinglePath

## Issue SCSI Rescan command to VDS service on Netbackup Server

## and force a rescan loop if first SCSI scan does not see new device

#

$logtime = Get-Date -format MMddyyyy-HH:mm:ss

Write-Host $logtime  "  Issuing SCSI Bus rescan to Virtual Disk Service (VDS) on server $NBUservername" 

Rescan-DiskDevice -Server $NBUservername -RescanDelay 60

$replaydisk = Get-DiskDevice -SerialNumber $replayview.SerialNumber -Server $NBUservername

if($replaydisk -eq $null)

{

 $scancount = 0

 $logtime = Get-Date -format MMddyyyy-HH:mm:ss

 Write-Host $logtime "  First SCSI Bus rescan on server $NBUservername did not find new Replay View Volume" 

 

 do

 {

  Rescan-DiskDevice -Server $NBUservername -RescanDelay 30

  $scancount ++

  $logtime = Get-Date -format MMddyyyy-HH:mm:ss

  Write-Host $logtime  "  Issued SCSI Bus rescan number $scancount on server $NBUservername" 

  $replaydisk = Get-DiskDevice -SerialNumber $replayview.SerialNumber -Server $NBUservername

 }

 until ($replaydisk -ne $null -or $scancount -eq 9)

 

 if($scancount -eq 9 -and $replaydisk -eq $null)

 {

  Break

 }

}

$logtime = Get-Date -format MMddyyyy-HH:mm:ss

Write-Host $logtime  "  SCSI rescan on $NBUservername found new Replay View Volume" 

## Check to see if new device was scanned in with a default access path

## eg. a drive will sometimes automatically take the next available drive letter

#

if($replaydisk.AccessPath -eq $null)

{

## Mount new device with specified AccessPath of $NBUmountpoint for backup

#

$logtime = Get-Date -format MMddyyyy-HH:mm:ss

Write-Host $logtime  "  Mounting Replay View Volume to mountpoint $NBUmountpoint" 

Add-VolumeAccessPath -Server $NBUservername -SerialNumber $replayview.SerialNumber -AccessPath $NBUmountpoint

}

else

{

## Remove the default access path if necessary

#

$logtime = Get-Date -format MMddyyyy-HH:mm:ss

Write-Host $logtime  "  New Volume was scanned in with default Access Path of $DiskDevPaths - Removing default access path" 

Remove-VolumeAccessPath -Server $NBUservername -SerialNumber $replayview.SerialNumber -AccessPath $replaydisk.AccessPath -Confirm:$false

## Mount new device with specified AccessPath of $NBUmountpoint for backup

#

$logtime = Get-Date -format MMddyyyy-HH:mm:ss

Write-Host $logtime  "  Mounting Replay View Volume to mountpoint $NBUmountpoint" 

Add-VolumeAccessPath -Server $NBUservername -SerialNumber $replayview.SerialNumber -AccessPath $NBUmountpoint

}

## Stop Logging and exit script

stop-transcript

exit

kalord - Sorry - that was only half the process.  I gave you the PRE backup script - here is the POST

 

##########################################################################

# SCRIPT PARAMETERS                                                                          

# ONLY MODIFY THESE VARIABLES - DO NOT HARDCODE INTO SCRIPT!!!                                   

#                                                                                                

# $SCHostName - The name of the Storage Center containing the source volume                      

# $SRCservername - The server the source volume is mapped to                                     

# $SRCvolumename - The name of the volume (as displayed in the Enterprise Manager)               

# $ReplayMinsTTL - The expiration time (in mins) of the new Replay

# $NBUSrvLun - the LUN number to use when mapping the Replay View to the NBU server            

# $NBUServername - the name of the NBU server mounting the new Replay View                      

# $DESCreplay - a short Description of the newly created Replay                                 

# $replayviewname - the name of the new View Volume created from the Replay              

# $NBUmountpoint - mount point on the NBU Server for new Replay View (must be NTFS empty folder) 

# $SCNBUFolder - the Volume Folder on the Storage Center to place the new View in              

###########################################################################

$SCHostName = "COMPELLENTSC1"

$SRCservername = "HOST_A"

$SRCvolumename = "HOST_A_VOLUME1"

$ReplayMinsTTL = "10"

$NBUSrvLun = "99"

$NBUservername = "HOST_BKP_SRV"

$DESCreplay = "HOST_A_VOLUME1 NBU Replay"

$replayviewname = "HOST_A_VOLUME1 NBU View"

$NBUmountpoint = "C:\BACKUPS\HOSTAVOL1"

$SCNBUFolder = "NBU"

 

## Create new logfile based on script name and current date/time

#

$dt = Get-Date -format "yyyyMMdd_hhmm"

$log = ($MyInvocation.MyCommand.Name).Replace(".ps1","_$dt.log")

$PSLogFile = "C:\BACKUPS\logs\POST_" + $log

 

## Start transcript of all activities and set trap to stop transcript if a break is encountered

#

start-transcript $PSLogFile

trap { stop-transcript; break }

 

## Add the Compellent Powershell Commandlet SnapIn

Add-PSSnapin Compellent.StorageCenter.PSSnapin

 

#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 = "SilentlyContinue"

 

$pass = ConvertTo-SecureString (Get-Content c:\PSscripts\cmp_pwd.txt)

Get-SCConnection -HostName $SCHostName -User Admin -Password $pass -Save $SCHostName

Get-SCConnection -Name $SCHostName -Default

 

## Remove the Volume Access Path ***BEFORE*** removing mapping or rescanning SCSI Bus

## otherwise the OS will delete the mountpoint folder - sleep for 20 seconds to make

## sure this completes.

#

$logtime = Get-Date -format MMddyyyy-HH:mm:ss

Write-Host $logtime "  Removing Volume Access Path (mountpoint) $NBUmountpoint"

Remove-VolumeAccessPath -Server $NBUservername -AccessPath $NBUmountpoint -Confirm:$false

sleep 60

 

## Remove mapping of Replay View LUN from server on the Compellent

#

$logtime = Get-Date -format MMddyyyy-HH:mm:ss

Write-Host $logtime "  Removing mapping of $replayviewname from $NBUservername"

$NBUServerObj = Get-SCServer -Name INCOBU02

$NBUVolMapObj = Get-SCVolume -Name $replayviewname

Get-SCVolumeMap -SCVolume $NBUVolMapObj -SCServer $NBUServerObj | Remove-SCVolumeMap -Confirm:$false

 

## Delete the Replay View Volume on the Compellent

#

$logtime = Get-Date -format MMddyyyy-HH:mm:ss

Write-Host $logtime "  Removing Replay View $replayviewname on $SCHostName"

Get-SCVolume -SCVolume $NBUVolMapObj | Remove-SCVolume -Confirm:$false -SkipRecycleBin

 

## Now issue a SCSI Rescan to remove definition of the device on the Server OS

#

$logtime = Get-Date -format MMddyyyy-HH:mm:ss

Write-Host $logtime "  Issuing SCSI Bus rescan to Virtual Disk Service (VDS) on $NBUservername"

Rescan-DiskDevice -Server $NBUservername -RescanDelay 60

 

## Script completed successfully - stop logging and end with a clean exit

#

$logtime = Get-Date -format MMddyyyy-HH:mm:ss

Write-Host $logtime "  NBU Post script cleanup complete - exiting script..."

stop-transcript

exit

lboucher - These script works great.  I have adapted them for our BackupExec 2010 environment. 

There is only one issue that I am having with the Pre Backup script, which is that the replay drive does not come online on the server and therefore cannot mount it.

Any ideas on why this is happening and how it can be fixed?

Thanks,

Leo

kalord - We've seen the same issue and believe it has something to do with communication with the MS VDS service.  It works a majority of the time, but there are times when the rescan does not bring in the new volume and mount it and usually a reboot or a restart of the Virtual Disk Service fixes it.  I haven't played with it since the new PS command set was released.  I'll let you know what I find.

Thanks

lboucher - I rebooted the server after the Pre Backup script ran, but the drive still did not come online, nor did it mount.  I also inserted a powershell command to restart the virtual disk service on the server before mounting the drive, but that didn't work either. 

I ran the same script on another server and it working properly. 

I came up with a workaround, which I can currently trying, which is to add three powershell command before the script ends, which brings the drive online, clears the read-only attribute from the drive and assigned a drive letter.  Here are my powershell statements:

"select disk 4", "online disk" | diskpart

"select disk 4", "attributes disk clear readonly" | diskpart

"select disk 4", "select volume 7", "assign letter=v" | diskpart

 

Of course, this only works if the disk keeps coming in as disk 4.

Leo

No Responses!
No Events found!

Top