Backing up nzbdrone database

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?

It’s much better to let the built-in backup feature do it.
Sonarr already makes a weekly backup and prior to every automatic update. But i’ll assume that’s not enough for you. (No, the interval is hardcoded and thus cannot be changed)
You can trigger it manually via the System->Backups UI. The UI is built on top of the api, so anything the UI can, you can automate via the api.

The api is REST-based, in this case POST /api/command with JSON content and GET /api/command/{id}. I usually just check out the UI api call in the chrome dev console, also… the command processing is async, you’ll have to use GET to check the status of the running command. I suggest you check the wiki for more information.
After that you’ll just have to sync the Backups directory in the application data directory to your preferred backup location.

Personally I would just settle for the weekly backup and sync the backups directory to external storage.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.