A Powershell script with the following features has been created.
1. The folder on the mounted recovery point to be restored is selected using a .Net Windows.Forms FolderBrowserDialog (i.e. c:\Mounts\C__\Data)
2. Once the folder is selected, the folders and files containing it are listed in a Gridview. The user can select those he wants restored.
3. The destination Folder for the restore is selected using a .Net Windows.Forms FolderBrowserDialog
4. The Logs folder -- containing verbose logs for each of the objects copied by Robocopy is selected using a .Net Windows.Forms FolderBrowserDialog
The script can be run in normal mode for smaller jobs and in failsafe mode which is recommended for large jobs.
Switching between the two modes is done by launching the script with the -failsafe parameter for failsafe settings or without any parameters for the normal mode.
Once the script is launched the user is prompted to choose the elements mentioned at #1 to #4. If the script is launched in normal mode, the full information regarding the restore operation is shown on the screen and committed to logs. In failsafe mode, only the main objects selected at #2 are shown on the screen but the full data is collected in the logs.
Both options restore with the original permissions and, if the destination contains previous similar files, only the permissions are refreshed. This allows interrupted operations to be resumed without copying everything alloveragain.
After the restore operation, the logs are consolidated in a file called globallog.txt located in the logs folder and the globallog.txt file is automatically opened on the screen. This allows quickly identifying the possible errors. The individual logs are kept as well.
Help for the script is available by running:
get-help robocopy3.ps1
The code is presented below between horizontal lines and attached to the KB.
_____________________________________________________
<#
.Synopsis
Powershell Wrapper for copying with permissions using Robocopy
.Description
Mount the recovery points in a folder with a short name (i.e. c:\M\C__). This needs to be done in order to reduce the length of Windows Path Files.
.Parameter failsafe
The script uses fail-safe values. Use it for large restores.
.Example
robocopy3.ps1 -failsafe
#>
param (
[switch]$failsafe=$false
)
Add-Type -AssemblyName System.Windows.Forms
cls
Write-Host "Restore Files with Permissions using Robocopy`r`n_____________________________________________`r`n"
#Select root object to restore
$s = New-Object System.Windows.Forms.FolderBrowserDialog -Property @{Description = "Select the root folder to Restore:"; ShowNewFolderButton=$false}
$s.selectedpath = "c:\"
if (!($s.ShowDialog( )-eq [System.Windows.Forms.DialogResult]::OK)){Write-Host "Exiting..." -f yellow; Exit}
$sourcefolder = $s.SelectedPath
$zsources = @()
$xsourceobjects = get-childitem -path $sourcefolder
foreach($sourceobject in $xsourceobjects){
if ($sourceobject.psiscontainer){$label="Folder";$size=""}else{$label="File";$size=("{0:N2} KB" -f $($sourceobject.Length/1KB))}
$line=[pscustomobject]@{Type=$label;Name=$sourceobject.Name;Created=$sourceobject.CreationTime;LastWritten=$sourceobject.LastWriteTime;LastAccessed=$sourceobject.LastAccessTime;Size=$size;Path=$sourceobject.FullName}
$zsources += $line
}
$sources = $zsources| Out-GridView -Title "Select the objects (folders and/or files) to restore from the root folder:" -PassThru
if($sources -eq $null){Write-Host "Exiting..." -f yellow; Exit}
#get the list of folders
Write-Host "`r`n Objects to Restore"
$sources | ft -AutoSize -Wrap
#set the destination
$d = New-Object System.Windows.Forms.FolderBrowserDialog -Property @{Description = "Select or Create the destination folder:"; ShowNewFolderButton=$true}
$d.selectedpath = "c:\"
if (!($d.ShowDialog( )-eq [System.Windows.Forms.DialogResult]::OK)){Write-Host "Exiting..." -f yellow; Exit}
$xdestination = $d.SelectedPath
Write-Host "Destination Folder: $xdestination"
#set the log path
$L = New-Object System.Windows.Forms.FolderBrowserDialog -Property @{Description = "Select or Create the Logs folder. Must be empty"; ShowNewFolderButton=$true}
$L.selectedpath = "c:\"
if (!($L.ShowDialog( )-eq [System.Windows.Forms.DialogResult]::OK)){Write-Host "Exiting..." -f yellow; Exit}
$rootlogfile = $L.SelectedPath
Write-Host "Logs Folder: $rootlogfile`r`n"
#process folders
foreach ($sr in $Sources){if($sr -ne $null){
$source=$sr.path
$destination = "$($xdestination)\$($sr.name)"
$logfile = ("$($rootlogfile)\LOG_$($sr.name).txt").replace(" ",".")
if ($sr.type -eq "Folder"){$wildcard = "*.*";$emptydir="/E";}else{$wildcard=$sr.name;$emptydir=""; $source = Split-path $sr.path -parent; $destination= "$xdestination"}
if (!($failsafe)){
#High Resource Robocopy Command Line
robocopy.exe $source $destination $wildcard /B $emptydir /CopyAll /SecFix /MT:16 /Log:$logfile /V /FP /ETA /Tee /R:1
}
else {
#Low Resource Robocopy Command Line
robocopy.exe $source $destination $wildcard /B $emptydir /CopyAll /SecFix /MT:4 /Log:$logfile /V /FP /ETA /R:1
}
}
}
#global log
$logs = get-childitem $rootlogfile
Write-Host "`r`nConsolidating Logs...`r`n" -f Yellow
foreach ($log in $logs){
$log.Name
$z = get-content $log.FullName
$z >> "$rootlogfile\GlobalLog.txt"
}
Invoke-Item "$rootlogfile\GlobalLog.txt"
_____________________________________________________
ALTERNATE METHOD:
*NOTE: The Paste with Permissions command is installed with Rapid Recovery Core and Agent. It is not available in the Local Mount Utility.
To restore a directory or file and preserve permissions using Windows Explorer
1. Mount the recovery point that contains the data you want to restore. For details, see Mounting a Recovery Point for a Windows Machine.
2. In Windows Explorer, navigate to the mounted recovery point and select the directories and files that you want to restore. Right-click and select Copy.
3. In Windows Explorer, navigate to the machine location to where you want to restore the data. Right-click and select Paste with Permissions.
*NOTE: In this step, if the Paste with Permissions command is disabled on the right-click menu, then Windows Explorer is not aware of the files that you want to copy. Repeat Step 2 to enable the Paste with Permissions command on the right-click menu.