Skip to content

Instantly share code, notes, and snippets.

@asheroto
Last active December 11, 2024 09:52
Show Gist options
  • Save asheroto/0cbf775fb99de58082cbfd363a9469af to your computer and use it in GitHub Desktop.
Save asheroto/0cbf775fb99de58082cbfd363a9469af to your computer and use it in GitHub Desktop.
How to restore an offline OneDrive file. Resolving Issues with Restoring OneDrive Files from Image-Based Backups or Offline Drives.

Resolving Issues with Restoring OneDrive Files from Image-Based Backups or Offline Drives

Restoring files from an image-based backup or offline drives of a OneDrive folder can result in files appearing corrupted or inaccessible. This issue is often due to OneDrive's Files On-Demand feature, which stores placeholder files instead of the actual data locally. Additionally, even when files are fully downloaded, they may retain reparse point attributes that can prevent the files from opening correctly.

Common Scenarios Affected

This problem can occur with image-based backup solutions or when restoring files from offline drives if the backup includes placeholders instead of the actual file data. The following software are examples of those which may be impacted.

  • Acronis True Image or Cyber Protect
  • Macrium Reflect
  • Veeam Backup & Replication
  • Carbonite
  • Recuva
  • Windows Explorer may even be impacted

Example Error Messages

Error while opening an Excel spreadsheet (.xls, .xlsx)

image

The file format and extension of 'EMPLOYEE LIST.XLS' don't match. The file could be corrupted or unsafe. Unless you trust its source, don't open it. Do you want to open it anyway?

Error while opening a PDF in Adobe Acrobat

image

Adobe Acrobat could not open 'Payment Confirmation.pdf' because it is either not a supported file type or because the file has been damaged (for example, it was sent as an email attachment and wasn't correctly decoded).

Error while opening a JPG/PNG/GIF file in Photos

image

Sorry, Photos can't open this file because the format is currently unsupported, or the file is corrupted

How to Resolve the Issue

1. Verify File Content

Ensure that the files themselves contain actual data:

  • If the file size is 0 KB: This may indicate one of two issues:

    • The file has not been downloaded and is only available online due to OneDrive's Files On-Demand feature. In this case, you must download the file to your local storage before restoring it from a backup.
    • Alternatively, it could mean the file was not restored correctly through the backup software. For example, in Acronis True Image, simply copying and pasting the file via Windows Explorer will not work. Instead, open Acronis True Image, open the backup, navigate to the Recovery tab, and restore the file properly through the software interface. Once done, proceed with reparse point attribute removal.
  • If the file size is greater than 0 KB: The file has been downloaded locally and contains data, but it may still appear inaccessible due to reparse point attributes. In this case, proceed with reparse point attribute removal.

2. Remove the Reparse Point Attribute

If the file is downloaded and contains data but remains inaccessible, the issue is likely caused by a reparse point. To resolve this, copy and paste the functions from the Remove-ReparsePoints.ps1 script into PowerShell.

  • Use Remove-ReparsePoint to remove the reparse point attribute from an individual file:
Remove-ReparsePoint -Path "C:\Path\To\File"
  • Alternatively, use Remove-ReparsePointsInDirectory to remove reparse points from all files in a directory, with an optional -Recurse parameter to include subdirectories:
Remove-ReparsePointsInDirectory -Path "C:\Path\To\Directory" -Recurse

Additional Notes

  • After removing the reparse point, the file should be accessible as a regular file.
  • If issues persist, verify the backup integrity and ensure the OneDrive files were fully downloaded before the backup process.

By removing the reparse point, you ensure that the restored OneDrive files can be accessed correctly, resolving issues caused by placeholder files or reparse attributes.

Function Remove-ReparsePoint {
Param (
[parameter(Mandatory = $true)]
[string]$Path
)
$Item = Get-Item $Path -Force
if ($Item.Attributes -band [IO.FileAttributes]::ReparsePoint) {
$result = & fsutil reparsepoint delete "$($Item.FullName)"
if ($LASTEXITCODE -eq 0) {
Write-Host "Reparse point removed successfully from $($Item.FullName)"
} else {
Write-Error "Failed to remove reparse point from $($Item.FullName). Error: $result"
}
} else {
Write-Error "$($Item.FullName) is not a reparse point."
}
}
Function Remove-ReparsePointsInDirectory {
Param (
[parameter(Mandatory = $true)]
[string]$Path,
[parameter(Mandatory = $false)]
[switch]$Recurse
)
# Ensure the Remove-ReparsePoint function is defined
if (-not (Get-Command Remove-ReparsePoint -ErrorAction SilentlyContinue)) {
Write-Error "The Remove-ReparsePoint function is not defined. Please define it first."
return
}
# Get all items in the directory
$items = if ($Recurse) {
Get-ChildItem -Path $Path -Recurse -Force
} else {
Get-ChildItem -Path $Path -Force
}
# Process each item
foreach ($item in $items) {
if ($item.Attributes -band [IO.FileAttributes]::ReparsePoint) {
Write-Host "Processing: $($item.FullName)"
Remove-ReparsePoint -Path $item.FullName
}
}
Write-Host "Finished processing all items in $Path"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment