Solved

DPM 2010 Script to run inventory, then mark tape as free

Posted on 2011-09-04
5
2,184 Views
Last Modified: 2012-05-12
HI There,

We recently have setup a DPM 2010 Server backing up our corporate network.
Our server has a stand alone LTO 5 tape drive.
Our tape calendar is a full backup following the days:
Monday,Tuesday, Wednesday, Thursday, Friday 1, Friday 2, Friday 3, Friday 4, Friday 5
Along with Month Ends and Week Ends.
Because we are not the most organised bunch, we would like whatever tape that gets put it to be written to so I have been using the script attached below.
The script works fine but requires the manual input of server name and tape drive name. It also fails if an inventory is not run prior to the script being ran.

So my question is:
Can someone show me how to automate the following and add an inventory to the start of the the script so I can run it as a scheduled task before each night's backup.
My server Name is: STL-DPM1
My Tape Drive Name is: Hewlett Packard LTO Ultrium-5 drive

Here is the current script:

 }
 if (!$LibraryName)
 {
     $LibraryName = Read-Host "Library name: "
     if (!$LibraryName)
     {
         Write-Error "Library name 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}
 write-host "Getting library..."
 if (!$library)
 {
     Write-Error "Failed to find library with user friendly name $LibraryName"
     exit 1
 }
 foreach ($media in @(Get-Tape -DPMLibrary $library))
 {
 write-host "Getting media..."
 
        if ($media -is [Microsoft.Internal.EnterpriseStorage.Dls.UI.ObjectModel.LibraryManagement.ArchiveMedia])
         {
             foreach ($rp in @(Get-RecoveryPoint -Tape $media))
             {
   write-host "Getting recovery point..."
                 Get-RecoveryPoint -Datasource $rp.Datasource | Out-Null
                 Write-Verbose "Removing recovery point created at $($rp.RepresentedPointInTime) for tape in $($media.Location)."
                 write-host "Force removing recovery point..."
   Remove-RecoveryPoint -RecoveryPoint $rp -ForceDeletion -Confirm:$false
             }
             Write-Verbose "Setting tape in $($media.Location) as free."
      write-host "Setting tape as free..."
             Set-Tape -Tape $media -Free
         }
         else
         {
             Write-Error "The tape in $($media.Location) is a cleaner tape."
         }
   
 
}
0
Comment
Question by:St_Lukes
  • 3
  • 2
5 Comments
 
LVL 7

Expert Comment

by:d3ath5tar
ID: 36481908
if the script is running directly on your dpm server;

$DPMServerName = $env:computername (if you are running this remotely then replace $env:computername with a string value.

then get your library details
$DPMLibrary = get-dpmlibrary -DPMServerName $DPMServerName

The library in your tape unit would normally be listed as the second entry, which is entry 1 as the devices start at 0.... but you could run the above once manually to be sure.... but when you know the next line would be..

Start-DPMLibraryInventory -DpmLibrary $DPMLibrary[1] (unless 1 -i,e, the second device, wasn't your library locatioN)

You could also a -DetailedInventory to the command if you want a thorough one...



 
0
 

Author Comment

by:St_Lukes
ID: 36481947
d3ath5tar:

Thanks for the info, unfortunately I have no idea about this scripting so I was looking for someone to put it together for me cheers. I will be running it locally also.
0
 
LVL 7

Expert Comment

by:d3ath5tar
ID: 36482049
OK....

Open a powershell window and run;
set-remoteexecutionpolicy remotesigned
Close powershell

Each line of script will do the trick if you run it on your local dpm server so open notepad and paste in;

$DPMServerName = $env:computername
$DPMLibrary = get-dpmlibrary -DPMServerName $DPMServerName
Start-DPMLibraryInventory -DpmLibrary $DPMLibrary[1]

Save all that in c:\support\DoInventory.ps1 and launch it from a scheduled task before your backup kicks off...

To schedule a powershell job as a task, open scheduled tasks and create your task as teh command;
powershell -command "& C:\support\DoInventory.ps1' "

As far as working out if the $DPMLibrary[1] is correct; open powershel and run the first two lines manually
Then typr $DPMLibrary on it own; it will list all your back up objects e.g.

Tape something or other
Library name something or other
maybe more devices

Eahc line is a line starting from 0, so look for the line with your library name in it... it should be then second line which is 1.

If it is not one, replace one with the correct array line number remembering to count lines starting from 0.

0
 
LVL 7

Accepted Solution

by:
d3ath5tar earned 500 total points
ID: 36482056
Ohhhhh I frogot a bit....

the first line of DoInventory.ps1 needs to be;
Add-PSSnapin -name Microsoft.DataProtectionManager.PowerShell

So the whole file is;
Add-PSSnapin -name Microsoft.DataProtectionManager.PowerShell
$DPMServerName = $env:computername
$DPMLibrary = get-dpmlibrary -DPMServerName $DPMServerName
Start-DPMLibraryInventory -DpmLibrary $DPMLibrary[1]

0
 

Author Closing Comment

by:St_Lukes
ID: 36563845
Was a bit staggered and hard to follow. Required further assistance.
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You might have come across a situation when you have Exchange 2013 server in two different sites (Production and DR). After adding the Database copy in ECP console it displays Database copy status unknown for the DR exchange server. Issue is strange…
The recent Microsoft changes on update philosophy for Windows pre-10 and their impact on existing WSUS implementations.
This tutorial will walk an individual through locating and launching the BEUtility application and how to execute it on the appropriate database. Log onto the server running the Backup Exec database. In a larger environment, this would generally be …
This tutorial will walk an individual through locating and launching the BEUtility application to properly change the service account username and\or password in situation where it may be necessary or where the password has been inadvertently change…

680 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question