none
DPM 2010 PowerShell Script to Easily Restore Multiple Files

    Question

  • 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 not capable of being automated with the known values of the file to restore) 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, exact time unknown though)

    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.

    You can reach me at brian-at-mccleary-dot-com

    • Moved by MarcReynolds Friday, May 20, 2011 3:13 PM (From:Data Protection Manager)
    Monday, August 23, 2010 7:24 PM

Answers

  • Hi,

    Power-shell is very powerful, but with power, comes complexity - so it's not going to be an easy script to write.  With that said, you could simply enable end user recovery (EUR) and just have the users recover the files themselves.  

     

    You can restrict who has the ability to restore via a GP, or just restrict to make a copy of a file and not overwrite.

    • You can disable the Previous Versions tab on individual client computers.

    Note To view the Previous Versions tab, right-click the file that you want to restore on the network, and then click Properties . If the Previous Versions tab does not appear in the Properties dialog box, the Shadow Copies of Shared Folders feature may not be enabled on the shared resource. 
    • You can disable only the Restore button on the Previous Versions tab on individual client computers. 
    This functionality prevents a client from overwriting the current version of a file with an earlier version of the file. The client can only copy the earlier version of a file to an alternative location.

    To enable this functionality, you must add a DWORD registry entry to either of the following registry subkeys on the client computer. You must do this after you install the update on the client computer.

    HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Explorer
    HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer

    You can add the DWORD registry entry as part of a user's logon script.

    We recommend that you add the DWORD entry to the HKEY_LOCAL_MACHINE subkey. We recommend this for the following reasons: • The HKEY_LOCAL_MACHINE subkey is not overwritten by policy updates.
     
    • The HKEY_CURRENT_USER subkey can be written to by logon scripts that are using nonadministrator permissions. 

    To disable the Previous Versions tab
    To disable the Previous Versions tab on individual client computers, follow these steps: 1.  Click Start , click Run , type regedit in the Open box, and then click OK . 

    2.  Locate and then click either of the following registry subkeys:

    HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Explorer
    HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer
     
    3.  On the Edit menu, point to New , and then click DWORD Value . 
    4.  Type NoPreviousVersionsPage , and then press ENTER. 
    5.  Right-click NoPreviousVersionsPage , and then click Modify . 
    6.  In the Value data box, type 1 , and then click OK . 
    7.  Quit Registry Editor. 

    Alternatively, you can use the Reg.exe utility to disable the Previous Versions tab. To do this, type either of the following commands at the command prompt, and then press ENTER:

    REG ADD HKLM\Software\Microsoft\Windows\CurrentVersion\Explorer /v NoPreviousVersionsPage /t REG_DWORD /d 1
    REG ADD HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer /v NoPreviousVersionsPage /t REG_DWORD /d 1

    To disable the Restore button
    To disable only the Restore button on the Previous Versions tab on individual client computers, follow these steps: 1.  Click Start , click Run , type regedit in the Open box, and then click OK . 
    2.  Locate and then click either of the following registry subkeys:

    HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Explorer
    HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer 

    3.  On the Edit menu, point to New , and then click DWORD Value . 
    4.  Type NoPreviousVersionsRestore , and then press ENTER. 
    5.  Right-click NoPreviousVersionsRestore , and then click Modify . 
    6.  In the Value data box, type 1 , and then click OK . 
    7.  Quit Registry Editor. 

    Alternatively, you can use the Reg.exe utility to disable the Restore button. To do this, type either of the following commands at the command prompt, and then press ENTER:

    REG ADD HKLM\Software\Microsoft\Windows\CurrentVersion\Explorer /v NoPreviousVersionsRestore /t REG_DWORD /d 1
    REG ADD HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer /v NoPreviousVersionsRestore /t REG_DWORD /d 1

     

     


    Regards, Mike J [MSFT] This posting is provided "AS IS" with no warranties, and confers no rights.
    • Marked as answer by Parag Agrawal Wednesday, September 8, 2010 9:26 AM
    Monday, August 23, 2010 8:29 PM
    Moderator
  • Thanks Mike.  I appreciate the detail response, but that didn't help me.  As I stated, the need was to restore files deleted through a document management system.  The users don't have access to the file respository and therefore end user recovery is not an option.  After quite a bit of research, I was able to come up with a working powershell script for my needs.  It is listed below for anyone who has this same issue.

       <#

       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

       }

     

    • Marked as answer by bmccleary Wednesday, September 8, 2010 4:50 PM
    Wednesday, September 8, 2010 4:49 PM

All replies

  • Hi,

    Power-shell is very powerful, but with power, comes complexity - so it's not going to be an easy script to write.  With that said, you could simply enable end user recovery (EUR) and just have the users recover the files themselves.  

     

    You can restrict who has the ability to restore via a GP, or just restrict to make a copy of a file and not overwrite.

    • You can disable the Previous Versions tab on individual client computers.

    Note To view the Previous Versions tab, right-click the file that you want to restore on the network, and then click Properties . If the Previous Versions tab does not appear in the Properties dialog box, the Shadow Copies of Shared Folders feature may not be enabled on the shared resource. 
    • You can disable only the Restore button on the Previous Versions tab on individual client computers. 
    This functionality prevents a client from overwriting the current version of a file with an earlier version of the file. The client can only copy the earlier version of a file to an alternative location.

    To enable this functionality, you must add a DWORD registry entry to either of the following registry subkeys on the client computer. You must do this after you install the update on the client computer.

    HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Explorer
    HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer

    You can add the DWORD registry entry as part of a user's logon script.

    We recommend that you add the DWORD entry to the HKEY_LOCAL_MACHINE subkey. We recommend this for the following reasons: • The HKEY_LOCAL_MACHINE subkey is not overwritten by policy updates.
     
    • The HKEY_CURRENT_USER subkey can be written to by logon scripts that are using nonadministrator permissions. 

    To disable the Previous Versions tab
    To disable the Previous Versions tab on individual client computers, follow these steps: 1.  Click Start , click Run , type regedit in the Open box, and then click OK . 

    2.  Locate and then click either of the following registry subkeys:

    HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Explorer
    HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer
     
    3.  On the Edit menu, point to New , and then click DWORD Value . 
    4.  Type NoPreviousVersionsPage , and then press ENTER. 
    5.  Right-click NoPreviousVersionsPage , and then click Modify . 
    6.  In the Value data box, type 1 , and then click OK . 
    7.  Quit Registry Editor. 

    Alternatively, you can use the Reg.exe utility to disable the Previous Versions tab. To do this, type either of the following commands at the command prompt, and then press ENTER:

    REG ADD HKLM\Software\Microsoft\Windows\CurrentVersion\Explorer /v NoPreviousVersionsPage /t REG_DWORD /d 1
    REG ADD HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer /v NoPreviousVersionsPage /t REG_DWORD /d 1

    To disable the Restore button
    To disable only the Restore button on the Previous Versions tab on individual client computers, follow these steps: 1.  Click Start , click Run , type regedit in the Open box, and then click OK . 
    2.  Locate and then click either of the following registry subkeys:

    HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Explorer
    HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer 

    3.  On the Edit menu, point to New , and then click DWORD Value . 
    4.  Type NoPreviousVersionsRestore , and then press ENTER. 
    5.  Right-click NoPreviousVersionsRestore , and then click Modify . 
    6.  In the Value data box, type 1 , and then click OK . 
    7.  Quit Registry Editor. 

    Alternatively, you can use the Reg.exe utility to disable the Restore button. To do this, type either of the following commands at the command prompt, and then press ENTER:

    REG ADD HKLM\Software\Microsoft\Windows\CurrentVersion\Explorer /v NoPreviousVersionsRestore /t REG_DWORD /d 1
    REG ADD HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer /v NoPreviousVersionsRestore /t REG_DWORD /d 1

     

     


    Regards, Mike J [MSFT] This posting is provided "AS IS" with no warranties, and confers no rights.
    • Marked as answer by Parag Agrawal Wednesday, September 8, 2010 9:26 AM
    Monday, August 23, 2010 8:29 PM
    Moderator
  • Thanks Mike.  I appreciate the detail response, but that didn't help me.  As I stated, the need was to restore files deleted through a document management system.  The users don't have access to the file respository and therefore end user recovery is not an option.  After quite a bit of research, I was able to come up with a working powershell script for my needs.  It is listed below for anyone who has this same issue.

       <#

       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

       }

     

    • Marked as answer by bmccleary Wednesday, September 8, 2010 4:50 PM
    Wednesday, September 8, 2010 4:49 PM