-
-
Save p0w3rsh3ll/5de666b1986890919c47043c20e4c7e6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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