Skip to content

Instantly share code, notes, and snippets.

@p0w3rsh3ll
Created July 11, 2016 14:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save p0w3rsh3ll/5de666b1986890919c47043c20e4c7e6 to your computer and use it in GitHub Desktop.
Save p0w3rsh3ll/5de666b1986890919c47043c20e4c7e6 to your computer and use it in GitHub Desktop.
# 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
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment