Solved

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

Posted on 2011-09-04
5
2,131 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Was a bit staggered and hard to follow. Required further assistance.
0

Featured Post

Wish Marketing would stop bothering you?

Is your marketing department constantly asking for new email signature updates? Are they requesting a different design for every department? Do they need yet another banner added? Don’t let it get you down! There is an easy way to manage all of these requests...

Join & Write a Comment

Scenario:  You do full backups to a internal hard drive in either product (SBS or Server 2008).  All goes well for a very long time.  One day, backups begin to fail with a message that the disk is full.  Your disk contains many, many more backups th…
OfficeMate Freezes on login or does not load after login credentials are input.
This tutorial will give a short introduction and overview of Backup Exec 2012 and how to navigate and perform basic functions. Click on the Backup Exec button in the upper left corner. From here, are global settings for the application such as conne…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

763 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now