Tuesday, February 10, 2015

List unproteced volumes on your DPM-server

Hi folks,

Last week I encountered a customer that had a challenge that backup operators would add a production server to a protection group in DPM but not protect all necessary volumes on the production server.

To solve their challenge I created a PowerShell-script that queries all protected servers and compare what volumes they have with the protected volumes in DPM. The result of the script is a list with the server name and drive letter on the volume that is not protected.

# Create folder for output-files
New-item C:\Temp\DPM\Scripts -type directory -force | Out-Null

# Clears all content in output-files, if exists
Clear-Content C:\Temp\DPM\Scripts\AllVolumes.txt
Clear-Content C:\Temp\DPM\Scripts\ProtectedVolumes.txt
Clear-Content C:\Temp\DPM\Scripts\NotProtectedVolumes.txt

# Get all servers that is present in any Protection Groupp
$Allps = Get-ProductionServer | where { $_.ServerProtectionState -eq "HasDataSourcesProtected" }

# Gets all Protection Groups
$pg=Get-ProtectionGroup -DPMServerName (&hostname)

# Gets all protected Volumes
foreach ($ps in $pg) { GET-DataSource -ProtectionGroup $ps | where { $_.ObjectType -eq "Volume" } | Select Computer,Name | ft -HideTableHeaders | out-file -Width 50 C:\Temp\DPM\Scripts\ProtectedVolumes.txt -Append }

# Gets all available Volumes
foreach ($Allps1 in $Allps) { Get-DPMDatasource -ProductionServer $Allps1 -Inquire | where { $_.ObjectType -eq "Volume" } | Select Computer,Name | ft -HideTableHeaders | out-file -Width 50 C:\Temp\DPM\Scripts\AllVolumes.txt -Append }

# Removes empty lines and sort data from output-files
(gc C:\Temp\DPM\Scripts\ProtectedVolumes.txt) | ? {$_.trim() -ne "" } | Sort-Object | Set-Content C:\Temp\DPM\Scripts\ProtectedVolumes.txt
(gc C:\Temp\DPM\Scripts\AllVolumes.txt) | ? {$_.trim() -ne "" } | Sort-Object | Set-Content C:\Temp\DPM\Scripts\AllVolumes.txt

# Compare protected volumes with all volumes and exports not proteced volumes

Compare-Object $(Get-Content C:\Temp\DPM\Scripts\ProtectedVolumes.txt) $(Get-Content C:\Temp\DPM\Scripts\AllVolumes.txt) -PassThru | out-file -Width 50 C:\Temp\DPM\Scripts\NotProtectedVolumes.txt -Append

Remember to run the code in an elevated DPM Shell and if you want to use the script for another data-source rather then volumes: Change the "Volume" to for example "System Protection" in line 14 & 17. Example: { $_.ObjectType -eq "System Protection" }

Take care! //Markus

No comments :

Post a Comment