Backup/Restore a local Windows Internal Database

I’ve got Direct Access servers where I want to backup the local Windows Internet Database.

The built-in VSS (Volume Shadow Copy Services) has 3 components:
VSS-components

Let’s see if there’s a writer for the Windows Internal Database component (WID)

vssadmin list writers | 
Select-String -Pattern "Writer\sname:\s" -Context 0,3 |
ForEach-Object {
    [pscustomobject]@{
        Id = (($_.Context.PostContext -split "\r\n")[0] -split ':')[1].Trim()
        Name = ($_.Line -split ':\s',2)[1] -replace "'",''
    }
} | Select Name,Id | ft -AutoSize

VSS-writers
Fortunately, there’s a WIDWriter in the above list 😀

It also means that the built-in tools are able perform a live backup. But, I first need to add the Windows Backup feature:

Add-WindowsFeature Windows-Server-Backup  -Restart:$false

Now, I’m ready to backup and restore the internal database files.
The backup operation will create a WindowsImageBackup directory on the target partition (P: in my case).
The recovery operation will extract files from the VHD previously created. It will not restore files in their original location under C:\Windows\…
but will rather move them to another folder (P:\BackupDB) and preserve the original folders tree.
VSS-restore-location

# Backup Direct Access Database using Volume Shadow and Windows built-in backup tools
'WID\Data','WID\Log','DirectAccess\db' | ForEach-Object {
if (-not(Test-Path -Path $_ -PathType Container)) {
mkdir "P:\BackupDB\$($_)"
}
}
try {
$pol = New-WBPolicy -ErrorAction Stop
Add-WBBackupTarget -Policy $pol -Target (New-WBBackupTarget -VolumePath P:) -ErrorAction Stop
Add-WBFileSpec -Policy $pol -FileSpec (New-WBFileSpec -FileSpec C:\windows\WID\* ) -ErrorAction Stop
Add-WBFileSpec -Policy $pol -FileSpec (New-WBFileSpec -FileSpec C:\Windows\DirectAccess\* ) -ErrorAction Stop
Set-WBSchedule -Policy $pol -Schedule ([datetime]::Now.AddMinutes(10)) -ErrorAction Stop
Start-WBBackup -Policy $pol -ErrorAction Stop
} catch {
Write-Warning -Message "Failed to backup because $($_.Exception.Message)"
}
$Backups = Get-WBBackupSet -BackupTarget (New-WBBackupTarget -VolumePath P:)
$Backup = $Backups | Select -Last 1
if ((Get-WBJob -Previous 1).HResult -eq 0) {
'WID\Data','WID\Log','DirectAccess\db','DirectAccess' | ForEach-Object {
$FilesPath = Join-Path -Path (
Get-WBBackupVolumeBrowsePath -BackupSet $Backup -VolumeInBackup $Backup.Volume[0]
) -ChildPath "Windows\$($_)\*"
$Loc = $_
Get-ChildItem -Path $FilesPath | ForEach-Object {
Start-WBFileRecovery -BackupSet $Backup -SourcePath "$($_.FullName)" -TargetPath "P:\BackupDB\$($Loc)" -Force -Recursive -Option OverwriteIfExists -Verbose
}
}
}

Quick ‘n dirty solution but it allowed me to extract the database files in a consistent way using only the built-in tools and the capabilities of the Volume Shadow Copy Services (VSS).

4 thoughts on “Backup/Restore a local Windows Internal Database

  1. Pingback: VSSAdmin Writers in Powershell überführen | Das nie endende Chaos!

  2. Pingback: SOLVED: Everything You Need To Know About the Windows Internal Database (WID) - Up & Running Technologies, Tech How To's

  3. This is all fine and dandy but you did not describe how to actually restore the database as the working copy. you do backups in the event that the working copy gets corupted. So how do you actually restore this backup to be the working copy? I’ve been informed by Microsoft that it is not possible to so. Are they wrong?

    • Hello,

      It’s hard to tell if they are wrong or not if there’s no evidence of this statement.
      Even though you’d have an official link to this statement, it would just mean that they don’t provide support for any scenario or solution.
      It doesn’t mean, you can’t do it and that you won’t succeed.
      Before doing and attempting anything “out-of-support”, I’d recommend to have a full backup of your machine.
      I’d even recommend that you first try the WID db restore on a clone VM, just to test it.

      So, I see two ways to perform the restore.
      1. is the cold boot method. You boot a WinPE and just replace the current files with those extracted from the backup.
      2. is using the SQL management studio where you’d first stop services related to the db, then connect to the WID db, detach files and attach the files.
      Here’s an example with WSUS to find the way with some screenshots of the SQL management studio
      https://docs.microsoft.com/en-us/windows-server/administration/windows-server-update-services/manage/wid-to-sql-migration
      You can probably find more content online about the various ways to use this tool.

      If you ever explore one or both scenario that I previously mentioned, I’d like you to post back a comment on your journey.
      Good luck 🙂

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.