I run Nzbdrone on a Windows 2012 machine and wish to backup the database nightly. I have written a Powershell script but it sometimes fails:
The process cannot access the file because it is being used by another process.
The file I am trying to backup is:
“c:\programdata\nzbdrone\nzbdrone.db”
and the code is:
$nzbdrone = Get-Process nzbdrone* -ErrorAction SilentlyContinue Write-Host `$nzbdrone $nzbdrone.GetType() Write-Host `$nzbdrone $nzbdrone.Threads
if ($nzbdrone) { Write-Host "Try graceful stop nzbdrone" $nzbdrone.CloseMainWindow() Sleep 5 if (!$nzbdrone.HasExited) { Write-Host "Trying to force nzbdrone down" Get-Service NzbDrone | Stop-Process -Force -PassThru } }
How should this be done?