Script to permanently delete shows that are waiting to be deleted

This week I wanted to transfer my DVR files from one harddrive to another but had several terabytes of shows waiting to be deleted because of the 7 day limbo that files go into after being deleted. I started permanently deleting shows via the web interface under the /admin/recordings/files/deleted path but there were over 800 of them and so I automated the process with a script. There's probably an easier way to do this but I couldn't figure it out. Here's the script I wrote:


set -e

IDS=$(curl http://dvr.local:8089/dvr/files?all=true | jq '.[] | select(.DeleteScheduledFor != 604800000) | .ID')

for quoted_id in ${IDS//\n/ } ; do
id=$(echo $quoted_id | sed 's/"//g')
echo $id
curl -XPUT http://dvr.local:8089/dvr/files/$id/permanently_delete
sleep 10

Oh yeah, the sleep is in there because doing it too quickly crashes the Channels DVR and then I have to restart my Synology NAS to get it to start again.

Using -r with jq may help with the string processing you had to do.

I’ll have to investigate what would have caused the situation that you describe that caused the DVR to crash.

Do you still have the DVR logs from that time with anything mentioning panic?

Thanks for the -r tip! Here's the error I keep getting:

[GIN] 2020/02/11 - 20:17:39 | 200 | 458.989382ms | | PUT /dvr/files/1461/permanently_delete
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xc67a28]

goroutine 75 [running]:*File).Refresh(...)[email protected]/dvr/file.go:136*Recorder).RunProcessor(0xc00000c5a0)[email protected]/dvr/recorder.go:374 +0xa18
created by*Recorder).Run[email protected]/dvr/recorder.go:168 +0xa9

This has been fixed in the latest DVR beta. Please try that out. You should be able to remove your sleep after that.


Are you saying that the current DVR Server beta doesn't delete recordings immediately. It holds them for seven days and then deletes them?

Correct. Please see:

Within the last hour, a setting has been added to choose how long an item stays in the trash. 1, 3, or 10 days. It defaults to 10 days.