Showing posts with label Scripts. Show all posts
Showing posts with label Scripts. Show all posts

Wednesday, October 7, 2009

Tape library inventory using Powershell

The command to start a fast or detailed inventory using Powershell is not to difficult, the trick is to get the correct name for the tape library.
In the example below we use an additional Powershell command to read the Library name in to a variable.  

First we need to list all tape libraries attached to the DPM server. When you have a Tape library attached, you might see the drive listed as well. Note the order the tape libraries are listed.
(replace dpm01 with the name of your DPM server)

PS > get-dpmlibrary -DPMServerName dpm01

Name                                     Drives                   Slots          I/E ports
----                                     ------                   -----               ---------
Stand-alone Drive: I...                       1                    0                 0          #0
Library: Library1                             2                      23                1          #1

Now we read the library details in to the variable $DPMlib
(replace dpm01 with the name of your DPM server)

$dpmlib = get-dpmlibrary -DPMServerName dpm01

Using the information collected with the first command we now can start the inventory. The number added to the $DPMlib variable is the order number in which the library is listed, start counting with 0. In this example, the number 1.

Fast inventory:

PS > Start-DPMLibraryInventory -DpmLibrary $dpmlib[1]

JobCategory                        Status                             HasCompleted
-----------                             ------                                  ------------
FastInventory                      Scheduled                            False

Detailed inventory:

PS > Start-DPMLibraryInventory -DetailedInventory -DpmLibrary $dpmlib[1]

JobCategory                        Status                                  HasCompleted
-----------                             ------                                  ------------
DetailedInventory                Scheduled                               False

When you use it in a script it will look like this

$dpmlib = get-dpmlibrary -DPMServerName dpm01
Start-DPMLibraryInventory -DpmLibrary $dpmlib[1]

Tuesday, October 6, 2009

Migrate protection data

There are some cases you might need to migrate your protection data to a new disk. DPM Sp1is shipped with a Powershell script that allows you to migrate your protection data to new storage.
For this you need to follow these steps:

First get a list of disks attached to your DPM server; pay attention to the order the disks are listed 

Start the DPM Management Shell

PS> get-dpmdisk –dpmservername DPM01

Name          Status            NtDiskId Total Capaci Unallocated  Type
                                                   ty        Space
----          ------            -------- ------------ ------------ ----
COMPAQ MSA... Healthy               3       732 GB       582 GB Basic          #0
COMPAQ MSA... Healthy               4       732 GB       582 GB Basic          #1
VMware Vir... Healthy               1        50 GB        28 GB Basic               #2
VMware Vir... Healthy                2         5 GB         0 GB Basic                 #3

Read the disk order in to a variable ($disk)

PS > $disk = Get-DPMDisk -DPMServername dpm01

Now you can use the script MigrateDatasourceDataFromDPM.ps1. First find the disk number of the source disk, these numbers are not displayed when you use the get-dpmdisk command. Do not get fooled by the NTdiskID, you do not need those. You just need to count the disks listed starting with 0 (see red numbers in example). Now find the number for the destination disk using the same trick.

In the example below we like to migrate the data from disk 2 to disk 1

PS > ./MigrateDatasourceDataFromDPM.ps1 -DPMServerName dpm01 -Source $disk[2] -Destination $disk[1]

More options and examples can be found on Technet

Tuesday, September 1, 2009

Script to resolve: Free tape threshold reached

When you have a tape library for which you change the tapes on a daily or weekly basis you properly run in to the following warning: Free tape threshold reached.

The number of free tapes in the Tape Library ,name> is less than or equals the threshold value of #. You must add tape to the library and it as free in order to prevent future backups from failing (ID 3305)

You receive this warning even when there are enough expired tapes available in the tape library. You get this warning because DPM checks the number of free tapes, in spite of the fact that DPM can write to expired tapes as well.
image

The advised resolution in DPM is manually mark all expired tapes as free. However a real IT-admin does not like manual labor. Therefore we created a PowerShell script that checks for expired tapes and marks them free.
If you run the script manually it looks like this:
image

Powershell script:

param ([string] $DPMServerName)
add-PSSnapin Microsoft.DataProtectionManager.PowerShell
if(("-?","-help") -contains $args[0])
{
    Write-Host "Description: This script marks all expired tapes as free"
    Write-Host "Usage: MarkExpiredTapesAsFree.ps1 [-DPMServerName] <Name of the DPM server>"
    exit 0
}
if (!$DPMServerName)
{
    $DPMServerName = Read-Host "DPM server name"
    if (!$DPMServerName)
    {
        Write-Error "Dpm server name not specified."
        exit 1
    }
}
if (!(Connect-DPMServer $DPMServerName))
{
    Write-Error "Failed to connect To DPM server $DPMServerName"
    exit 1
}
$libraryList = Get-DPMLibrary -DPMServerName $DPMServerName
foreach ($library in $libraryList)
{
    $expiredTapeList = @(Get-Tape -DPMLibrary $library |
    ? {$_ -is [Microsoft.Internal.EnterpriseStorage.Dls.UI.ObjectModel.LibraryManagement.ArchiveMedia] -and

$_.DatasetState -eq "Recyclable"})
    if ($expiredTapeList.Length -gt 0)
    {
        Write-Host "Marking $($expiredTapeList.Length) tape(s) as free in $($library.UserFriendlyName)."
        Set-Tape -Tape $expiredTapeList -Free
        $expiredTapeList | select Location
    }

}

We have scheduled this script to run daily using the Windows task scheduler. Expired tapes are now mark as free on a daily basis

In order to schedule a Powershell command you need to create a cmd that calls the Powershell script. The command file is listed below

command file:

powershell -command "& 'd:\ps_scripts\MarkExpiredTapesAsFree.ps1' <servername>"

Thanks to Mischa for his help with the script.

Thursday, August 20, 2009

Heavy Weight Consistency Check using PowerShell


David Allen has posted a interesting piece on performing consistency checks checks using Powershell. He also describes the difference between a standard and a Heavy Weight consistent check.

Read it all: http://www.scdpmonline.org/heavy-weight-consistency-check-using-powershell.aspx

Friday, July 17, 2009

Downloaded PowerShell Scripts won’t run


When you download PowerShell scripts from the internet you might find that they do not work on your local (DPM) Server.
The reason is PowerShell is configured to run in the most secure mode by default. This mode is the "Restricted" execution policy, in which PowerShell operates as an interactive shell only.

Error message:

The file C:\downloaded_script.ps1 cannot be loaded. The execution of scripts is disabled on this system. Please see "Get-Help about_signing" for more details

You can change this behavior with Set-ExecutionPolicy command in PowerShell

Example:

  • Set-ExecutionPolicy Allsigned (Runs only signed scripts)
  • Set-ExecutionPolicy Unrestricted (Runs all scripts signed and unsigned)

More options and information at: http://www.hanselman.com/blog/SigningPowerShellScripts.aspx

Tuesday, June 16, 2009

Mark tape as Free

DPM protects tapes that belong to a protection group from overwriting or 'mark as free' for the configured protection period.
This is a useful option and protects you against accidently overwriting tapes that should not be overwritten. But in a scenario your testing long-term protection or you just want to reuse tapes earlier, this can be a ignoring.



There is a work around for this by using a Powershell Script:




This is posted on the DPM blog site