Handling orphan recording files

I am in the process of moving from external USB drives to a NAS for DVR storage. As I'm doing this, I'm also purging a lot of old shows rather than moving them to reclaim space since they are reruns and easily recovered. What I'm finding is a lot of recordings that have already been deleted from the library over the years. This isn't a trash can issue, or the time it takes for the files to be eventually deleted. This is shows that were deleted through the Channels UI a long time ago that are still in the directors. Where the entire show is gone, its easy for me to manually delete the whole folder. But where its some episodes of a show, its a little more tedious.

Is there a way to have the system go clean up the drive and remove any recording it doesn't have in the library? Or, is there a way for it to just give me a list of them and I can delete them.

This could have happened over the years with me moving things and making mistakes, because I don't ever just delete recordings from the drive intentionally without doing it through the UI.

That would be a dangerous option for most users.

DVR web admin UI
DVR Database > Maintenance :gear: > Manage Recordings Database
They will be shown under Missing/Deleted

Thanks for the info.

Does this show database entries missing the recording file, or recording files missing the database entry. I tried it and it only showed one show. I am pretty sure I have a lot more than that recording files without entries.

Missing recording file.

To get all recordings DVR knows about:

$ curl -sS http://127.0.0.1:8089/dvr/files?all=true | jq '.[].Path'

All recordingds on disk:

$ find TV Movies -type f -name \*.mpg

from DVR directory.

Comparing the two will reveal orphan files.

Thanks for the suggestion. I've got a few thousand recordings so trying to do that on the command line might be tricky. My plan B will be to go through the shows and just compare the episodes in the library with the ones on the drive. Most of the files have the season and episode in the file name. Movies are a little easier.

Try this:

#!/usr/bin/bash

if [ ! -d TV ] || [ ! -d  Movies ] ; then
	echo Must be in the Channels recordings directory
	exit 1
fi

cmd1 () {
	curl -sS http://127.0.0.1:8089/dvr/files?all=true | 
	jq '.[].Path' |
       	sed -e 's/^\"\(.*\)\"$/\1/' -e 's/\\\\/\//g'
}

cmd2 () {
	find TV Movies -type f -name \*.mpg
}

diff -U 0  <(cmd1 | sort) <(cmd2 | sort) | grep -E 'TV|Movies'


The -r argument for jq may save some need for sed.

Thanks for the tips, but you guys are a little over my head here so if I go about trying these on the command line, is there anything I can break if I mistype something here? I'll google a bit on bash before proceeding, but just want to make sure I don't create a mess.

Thanks, I'm going to try that at some point in the future. Assuming I can do that through SSH for my Synology NAS?

Didn't know about -r, thanks. It makes things simpler but sed is still needed due to inconsistent path storage by DVR server. Sometimes backslashes are used. Once it is fixed sed would not be needed.
The new version is at https://controlc.com/a1f1faba

Once you're clear on the process involved, at the very least I would advise copy and pasting instead of manually typing, to reduce any risk of mistyping.

This is actually the content of a file which should be made executable.
The first line should be a clear giveaway.

What does this mean?

The output from
$ curl -sS http://127.0.0.1:8089/dvr/files?all=true | jq -r '.[].Path'

contains this:

TV/Two and a Half Men/Two and a Half Men S01E11 2003-12-15 Alan Harper Frontier Chiropractor 2022-11-12-2315.mpg
TV/Two and a Half Men/Two and a Half Men S08E09 2010-11-15 A Good Time in Central Africa 2022-09-26-2200.mpg
TV\Two and a Half Men\Two and a Half Men S08E12 2010-12-13 Chocolate Diddlers or My Puppys Dead 2022-05-09-2034.mpg
TV\Two and a Half Men\Two and a Half Men S07E16 2010-03-01 Tinkle Like a Princess 2022-05-08-1530.mpg

I think I was running this DVR on Windows for a while before switching to Debian?

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