Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I’ve got what I thought would be a simple task with Data Protection Manager 2010 that is turning out to be quite frustrating. I have a file server on one server and it is the only server in a protection group. This file server is the repository for a document management application which stores the files according to the data within a SQL database. Sometimes users inadvertently delete files from within our application and we need to restore them. We have all the information needed to restore the files to include the file name, the folder that the file was stored in and the exact date that the file was deleted. It is easy for me to restore the file from within the DPM console since we have a recovery point created every day, I simply go to the day before the delete, browse to the proper folder and restore the file. The problem is that using the DPM console, the cumbersome wizard requires about 20 mouse clicks to restore a single file and it takes 2-4 minutes to get through all the windows. This becomes very irritating when a client needs 100’s of files restored… it takes all day of redundant mouse clicks to restore the files.

Therefore, I want to use a PowerShell script (and I’m a novice at PowerShell) to automate this process. I want to be able to create a script that I pass in a file name, a folder, a recovery point date (and a protection group/server name if needed) and simply have the file restored back to its original location with some sort of success/failure notification. I thought it was a simple basic task of a backup solution, but I am having a heck of a time finding the right code.

I have seen the sample code at http://social.technet.microsoft.com/wiki/contents/articles/how-to-use-a-windows-powershell-script-to-recover-an-item-in-data-protection-manager.aspx that I have tried to follow, but it doesn’t accomplish what I really want to do (it’s too simplistic) and there are errors in the sample code. Therefore, I would like to get some help writing a script to restore these files.

An example of the known values to restore the data are:

   DPM Server: BACKUP01
   Protection Group: Document Repository Data
   Protected Server: FILER01
   File Path: R:\DocumentRepository\ToBackup\ClientName\Repository\2010\07\24\filename.pdf
   Date Deleted: 8/2/2010 (last recovery point = 8/1/2010)

Bonus Points:

If you can help me not only create this script, but also show me how to automate by providing a text file with the above information that the PowerShell script loops through, or even better, is able to query our SQL server for the needed data, then I would be more than willing to pay for this development.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Well, after much frustration and research, I have come up with a working script. For those that want to know how to do the same, the script below works well to restore any given file.

<#
Parameters: Folder Path, File to Restore, Deletion Date
Example Usage: 
.\RecoverFile.ps1 "ClientName\Folder\2010\02\03\" "mydoc.pdf" "2010-08-04 09:54:24.117" 
#>

$filePath = [IO.Path]::Combine("D:\ClientData\", $args[0] )
$fileName = $args[1]
$dateDeleted = Get-Date $args[2]

Write-Host "Restoring '" -NoNewLine
Write-Host $filePath -NoNewLine
Write-Host $fileName -NoNewLine
Write-Host "' which was deleted on '" -NoNewLine
Write-Host $dateDeleted -NoNewLine
Write-Host "'"

$recoveryDate = Get-Date $dateDeleted.AddDays(-1).ToShortDateString()
$pg = Get-ProtectionGroup -DPMServerName DPMSERVER01 | Where-Object {$_.FriendlyName -eq "Document Repository Data"} 
$ds = Get-Datasource $pg
$so = New-SearchOption -FromRecoveryPoint $recoveryDate.AddDays(-1).ToShortDateString() -ToRecoveryPoint $recoveryDate.ToShortDateString() -SearchDetail FilesFolders -SearchType exactMatch -Location $filePath -SearchString $fileName
$ri = Get-RecoverableItem -Datasource $ds -SearchOption $so
$ro = New-RecoveryOption -TargetServer CLIENTDATASERVER01 -RecoveryLocation OriginalServer -FileSystem -OverwriteType overwrite -RecoveryType Recover
$recoveryJob = Recover-RecoverableItem -RecoverableItem $ri -RecoveryOption $ro
#4.3 Wait till the recovery job completes
while (! $recoveryJob.hasCompleted )
{
    # Show a progress bar
    Write-Host "." -NoNewLine
    Start-Sleep 1
}
if($recoveryJob.Status -ne "Succeeded")
{
    Write-Host "Recovery failed" -ForeGroundColor Red
}
else
{
    Write-Host "Recovery successful" -ForeGroundColor Green
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.