Saturday, December 3, 2011

How-To: Force Expire Tape in DPM 2010

System Center Data Protection Manager (DPM) 2010 enables disk-based and tape-based data protection and recovery for servers such as SQL Server, Exchange Server, SharePoint, virtual servers, file servers, and support for Windows desktops and laptops. DPM can also centrally manage system state and Bare Metal Recovery (BMR).

Do you ever got yourself into a situation where you run out of backup tapes due to inappropriate backup strategy ? If your answer is yes, then you probably notice at the same time you are facing an issue and that you are desperately to expire a LTO tape which holding the oldest recovery point. And guess what... You can't do this using DPM 2010 Administrator Console...OUCH!!!

So, you are sitting in the dark, waiting any tape to expire and helplessly watching each and every scheduled backup failed. Well, this will not happen  anymore if you use a powershell as found in Microsoft TechNet's Library. The script contents is as below :

Code Begins Here

param ([string] $DPMServerName, [string] $LibraryName, [string[]] $TapeLocationList)
if(("-?","-help") -contains $args[0])
{
    Write-Host "Usage: ForceFree-Tape.ps1 [[-DPMServerName] <Name of the DPM server>] [-LibraryName] <Name of the library> [-TapeLocationList] <Array of tape locations>"
    Write-Host "Example: Force-FreeTape.ps1 -LibraryName "My library" -TapeLocationList Slot-1, Slot-7"
    exit 0
}
if (!$DPMServerName)
{
    $DPMServerName = Read-Host "DPM server name: "
    if (!$DPMServerName)
    {
        Write-Error "Dpm server name not specified."
        exit 1
    }
}
if (!$LibraryName)
{
    $LibraryName = Read-Host "Library name: "
    if (!$LibraryName)
    {
        Write-Error "Library name not specified."
        exit 1
    }
}
if (!$TapeLocationList)
{
    $TapeLocationList = Read-Host "Tape location: "
    if (!$TapeLocationList)
    {
        Write-Error "Tape location not specified."
        exit 1
    }
}
if (!(Connect-DPMServer $DPMServerName))
{
    Write-Error "Failed to connect To DPM server $DPMServerName"
    exit 1
}
$library = Get-DPMLibrary $DPMServerName | where {$_.UserFriendlyName -eq $LibraryName}
if (!$library)
{
    Write-Error "Failed to find library with user friendly name $LibraryName"
    exit 1
}
foreach ($media in @(Get-Tape -DPMLibrary $library))
{
    if ($TapeLocationList -contains $media.Location)
    {
        if ($media -is [Microsoft.Internal.EnterpriseStorage.Dls.UI.ObjectModel.LibraryManagement.ArchiveMedia])
        {
            foreach ($rp in @(Get-RecoveryPoint -Tape $media))
            {
                Get-RecoveryPoint -Datasource $rp.Datasource | Out-Null
                Write-Verbose "Removing recovery point created at $($rp.RepresentedPointInTime) for tape in $($media.Location)."
                Remove-RecoveryPoint -RecoveryPoint $rp -ForceDeletion -Confirm:$false
            }
            Write-Verbose "Setting tape in $($media.Location) as free."
            Set-Tape -Tape $media -Free
        }
        else
        {
            Write-Error "The tape in $($media.Location) is a cleaner tape."
        }
    }
}

Code Ends Here

To put this script into use
  1. Open a new Notepad file and copy the code above into it.
  2. Save the file as ForceFree.ps1.
  3. Copy ForceFree.ps1 to C:/Program Files/Microsoft/Microsoft Data Protection Manager/scripts .
  4. The syntax to run the script is ForceFree.ps1 -DPMServerName <Name of server> -LibraryName <Name of library> -TapeLocation <slot numbers>.
Sample of script execution

PS C:\Program Files\Microsoft DPM\DPM\Scripting> .\ForceExpire.ps1
DPM server name: : backupserver
Hewlett Packard LTO Ultrium-4 drive
Hewlett Packard MSL G3 Series library  (x64 based)
Library name (cut & paste from above): : Hewlett Packard MSL G3 Series library
(x64 based)
Tape location: : slot-2
Processing this slot list...
slot-2
The operation will remove the following recovery point(s) because they have dep
endencies on each other:
Datasource '\\?\Volume{9f6da658-f6f1-11df-8d4f-00155d000115}\' on targetcomputer1.xxx.xxx.xx:
Saturday, 5 November, 2011 10:31:28 AM
Monday, 7 November, 2011 11:52:13 PM
Wednesday, 9 November, 2011 4:03:54 AM
Wednesday, 9 November, 2011 9:47:34 PM
Thursday, 10 November, 2011 8:01:09 PM
Friday, 11 November, 2011 8:09:17 PM
Monday, 14 November, 2011 8:31:54 PM
The operation will remove the following recovery point(s) because they have dep
endencies on each other:
Datasource '\\?\Volume{dff33793-b735-11df-a919-00155d000225}\' on targetcomputer2.xxx.xxx.xx:
Sunday, 6 November, 2011 12:02:41 AM
Tuesday, 8 November, 2011 2:36:56 AM
Wednesday, 9 November, 2011 7:33:40 AM
Wednesday, 9 November, 2011 9:24:50 PM
Thursday, 10 November, 2011 11:04:38 PM
Friday, 11 November, 2011 10:01:35 PM
Monday, 14 November, 2011 8:09:52 PM
Tuesday, 15 November, 2011 8:00:30 PM


More details information can be found at http://technet.microsoft.com/en-us/library/ff399673.aspx


No comments: