Migrating recordings from ChannelsDVR machine to File Server

A long time ago, I was talking about how to separate the DVR metadata from the recordings.

As I left it, I was using symlinks on my BeeHive (ChannelsDVR machine) to point the C:\DVR\TV\ and C:\DVR\Movies\ directories over to file shares on ZULU (my Windows Server 2022). That worked fine most of the time, but resulted in duplicate listings of all recordings, and also made recordings fail if the connection to the server was temporarily borked.

A few months ago, I dropped the symlinks, letting BeeHive record directly to its internal SSD. Then I set up a Task Schedule task to move recordings to ZULU using RoboCopy. This was great, except for the fact that if the recording was in-process... for some reason ChannelsDVR didn't have the file opened in exclusive mode, so the move succeeded, but the recording was truncated (usually at 6 minutes in).

Today, I saw a batch file example from @Edwin_Perez over on the OliveTin scripts thread, and saw how to check if the DVR is recording... so my batch file has been updated and works SO MUCH BETTER now.

Save this file as MigrateRecordings.cmd in the ChannelsDVR data directory (I use C:\DVR) and then setup a Windows Task Scheduler to start it up during login and it will just stay running in a loop. I've got it setup to take the server name as a argument (and defaulting to \\ZULU if not supplied).

CD /d "%~dp0"

if [%1] NEQ [] if [%server%] EQU [] set server="%~1"
if [%server%] EQU [] set server=\\ZULU

set migrationneeded=yes

:loop
REM cls
title "Migrate Recordings"
curl.exe "http://127.0.0.1:8089/dvr" | findstr  /I /C:"Recording"
set recording=%ERRORLEVEL%

if %recording% EQU 0 set migrationneeded=yes

if %recording% NEQ 0 if %migrationneeded% EQU yes call :migrate

:resume
if %recording% NEQ 0 set migrationneeded=no
if %recording% EQU 0 timeout /T 300
if %recording% NEQ 0 timeout /T 3600
goto :loop

:migrate
robocopy %~dp0TV %server%\TV\         /XF ReadMe.txt /MOV /S /J /COPY:DT /DCOPY:DT /XX /IM /IT /FP /MINAGE:0 /R:3 /W:5 /TEE /NJH /UNILOG+:"%~dp0Logs\Migrate\TV.log" /UNICODE
robocopy %~dp0Movies %server%\Movies\ /XF ReadMe.txt /MOV /S /J /COPY:DT /DCOPY:DT /XX /IM /IT /FP /MINAGE:0 /R:3 /W:5 /TEE /NJH /UNILOG+:"%~dp0Logs\Migrate\Movies.log" /UNICODE

Here's the setup in Task Scheduler:

  1. Task definition Screenshot 2024-12-03 130823
  2. Triggers Screenshot 2024-12-03 131358
  3. Daily schedule to ensure it restarts at 05:00
  4. Ensures it runs at machine startup
  5. Actions (Start a Program) Screenshot 2024-12-03 131109
  6. MigrateFiles.cmd in C:\DVR with server name \\ZULU Screenshot 2024-12-03 131120
  7. Leave Conditions at defaults (since the DVR machine should be on AC at all times)
  8. Settings to ensure it auto-restarts Screenshot 2024-12-03 131213

This likely could be improve a bunch (perhaps with better busy detection), but at least this will stop the truncated recordings :slight_smile:

1 Like

Check for when DVR is not busy ..... return code 0 not busy

curl.exe "http://127.0.0.1:8089/dvr" | findstr  /I /C:"busy\":false"
set notbusy=%ERRORLEVEL%
1 Like

I thought about that... but will that trip up on people streaming?

That means that DVR is totally Idle no watching/remote streaming, no comskip in progress and no recording.

I have a lot to learn about robocopy.

Does the script shown above handle the case when the destination drive gets full?
Maybe one of the options of robocopy?

That would be safe time to move, for sure... I wonder if it would be possible to sense activity other than watchin/streaming... since folks watching isn't a big issue for me.

That is why I check for Recording when I force a backup as ... I only care when the dvr is done Recording nothings else. So you are good to go with what you have.

This is how I backup my movies to my NAS .... This way I get no partials ...

goto start
:loop
timeout 300
:start
CD /d "%~dp0"
curl http://127.0.0.1:8089/dvr | findstr  /I /C:"busy\":false"
set notbusy=%ERRORLEVEL%
rem set notbusy=1
if %notbusy% NEQ 0 goto loop
ROBOCOPY "W:\DVR\Movies" "\\MYCLOUDPR4100\MyShares\Imports\ChannelsDVR\Movies" /move /COPY:DT /minage:0 /e /R:2 /W:2
MD "W:\DVR\Movies"
goto loop
exit

Cool, thanks... I've tweaked my RoboCopy lines... we'll see how that runs for tonight's moves.

I my Scenario it moves the whole Movies folder so at the end of Moving it ... you have to create it hence the MD "W:\DVR\Movies" would be the same if moving the TV Folder "MD W:\DVR\TV"

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