Move recordings to NAS after X days? (1 Viewer)

xcalibur666

New Member
November 8, 2012
4
0
Home Country
Denmark Denmark
I've created a little batch script, which might be helpfull for others:

I record TV to c:\rec_tv
Recordings are moved to \\nas\rec_tv

in c:\rec_tv\ I've created a empty text file, named dont_delete.txt. If I do not have this file, robocopy will delete my c:\rec_tv folder when done moving recorded TV.

This I perform every morning and I automatically update my MySQL DB with correct entries to my NAS.

Code:
robocopy c:\rec_tv\ \\NAS\rec_tv /E /MOVE /XF dont_delete.txt
cd "c:\Program Files\MySQL\MySQL Server 5.1\bin"
mysql -uroot -pMediaPortal mptvdb -e "UPDATE recording SET fileName=replace(fileName,'C:\\rec_tv\\', '\\\\nas\\rec_tv\\') WHERE fileName LIKE 'C:%';"
 

thekiwi

MP Donator
  • Premium Supporter
  • January 26, 2007
    287
    16
    Gisborne
    Home Country
    New Zealand New Zealand
    I do something along these lines with SQL scripts in a Stored Procedure in the MsSQL Database.

    If the database entry has IsPartOfSeries = 'False' then the SP finds those entries where the current time is after the ProgramStopTime and then does the following:
    * Copies the file to my NAS (eg
    * Update the database record 'RecordingFileName' from its current (for eg)
    \\MEDIASERVER\DVB Recordings\The Incredibles\The Incredibles (10098561)_2012-11-25_19-00.ts
    to
    \\\\MEDIASERVER\My Recordings\Movies\The Incredibles\The Incredibles (10098561)_2012-11-25_19-00.ts

    It requires a bit of understanding in SQL and an ability to set the Provs right, as it uses XP_CMDSHELL eg,

    EXEC MASTER..XP_CMDSHELL @Commandstring, NO_OUTPUT

    where the @Commandstring is the Copy Command.
     

    xcalibur666

    New Member
    November 8, 2012
    4
    0
    Home Country
    Denmark Denmark
    xcalibur - that's neat, thanks. I meant to look at doing this ages ago and never got around to it.
    Actually, I'm having problems that they do fall out of recorded TV database anyway. Will try to find a fix..

    Did you manage to get this fixed?
    Unfortunately no :( Since I've upgraded to MediaPortal 1.3.0 beta, the enture recording database is emptied by Mediaportal every time I do the SQL update. I've tried to stop the service before updating the DB and restart it afterwards, but no luck.

    So at the moment I've just added the recorded folder to my video folder and watches recordings from there.

    There should soo much be an option in the TV server, to automatically import recordings, when they appear in a folder!
     

    TommySharp

    MP Donator
  • Premium Supporter
  • January 15, 2007
    322
    7
    43
    Auckland
    Home Country
    New Zealand New Zealand
    Are you sure it's your SQL that is causing the recording database to be emptied?

    I found that if I manually move a file out of the recording folder then it's pretty immediate that MP has seen the file is no longer present and removes it from the DB. Maybe there is a way to delay this?
     

    Statts

    New Member
    July 7, 2012
    4
    1
    44
    Home Country
    Australia Australia
    Hi all,

    Sorry to dig up an old thread, but this is REALLY pertinent to what I'd like to achieve with a setup I am currently putting together. Did anyone manage to find a way to get this working?

    Thanks in advance for any help.
     

    batsi

    Portal Member
    May 23, 2008
    10
    3
    Munich
    Home Country
    Germany Germany
    Hi Statts,

    I have a working solution for, errr, yeah probably almost two years, if I have a look at the dates of my postings in this thread. Some may judge it as very unsophisticated, but for me it's fine.

    These are the steps, how I set it up:
    1. Set up a user on the file server with same username/password as the user running MediaPortal on the MP PC
      (maybe you want to or have already set up Autologon on the MP PC for that user)
    2. Set up a CIFS/SMB file share on the server and grant read/write access to that user
    3. Change the user, the TVservices on the MP PC runs from SYSTEM to that user
      (needed for the TVService having write access on the file share)
    4. In the MP recording folder on the MP PC make a symbolic link to the UNC path of the server
      ("mklink /d D:\Recordings\Server \\server\share" from elevated cmd)
    5. Create a batch file on the MP PC with the content below
    6. Create a Scheduled Task that calls that batch every 15 mins
      (daily task, check "repeat every" with 15 mins for 1 day)
    Every time the batch is called by the scheduler, it first checks if another instance is already running, and skips if it is. If then the drive space on the source drive is less than configured in $MinFreeGB it copies the files and changes the entries in the MySQL database.

    This is in productive use at my MediaPortal and works very reliable. It works completely in background, and you won't recognize a difference if the recording is local or on the server. I have never had the case, that I wanted to access a recroding while it was copying.

    I hope, this helps you (or anyone else)

    Regards
    Bastian

    Code:
    @echo off
    SetLocal EnableDelayedExpansion
    
    set SOURCE=D:\Recordings
    set DEST=D:\Recordings\Server
    
    set MinFreeGB=40
    
    set logfile=D:\%~n0.log
    
    set mysqlDB=mptvdb
    set mysqlUser=root
    set mysqlPass=MediaPortal
    set mysqlEXE="%ProgramFiles%\MySQL\MySQL Server 5.1\bin\mysql.exe"
    
    set runPID=%tmp%\%~n0.pid
    
    if exist %runPID% goto:checkprog
    echo.> %runPID%
    
    call:checkfree %SOURCE%
    if %freespace% GTR %MinFreeGB% goto:end
    
    for /f "tokens=*" %%i in ('dir /b /od %SOURCE%\*.ts') do (
        call:log "Starting move - %%i"
        call:run "%SOURCE%\%%i">>%logfile%
        call:log "  Finished."
        goto:end
    )
    
    :run
    robocopy /MOV /R:0 /NFL /NDL /NP /NJH /NJS "%SOURCE%" "%DEST%" "%~n1.*"
    %mysqlEXE% -u%mysqlUser% -p%mysqlPass% %mysqlDB% --default-character-set=latin1 -e "update `recording` set `fileName` = '%DEST:\=\\%\\%~nx1' where `fileName` = '%SOURCE:\=\\%\\%~nx1'"
    goto:eof
    
    :checkfree
    for /f "tokens=2" %%s in ('wmic volume get DriveLetter^, FreeSpace ^| findstr "^%~d1"') do set freespace=%%s
    set freespace=!freespace:~0,-9!
    goto:eof
    
    :checkprog
    tasklist | findstr /i "robocopy.exe" 1>NUL 2>&1 || erase %runPID%
    goto:eof
    
    :log
    echo %DATE% %TIME% - %~1>>%logfile%
    goto:eof
    
    :end
    erase %runPID%
    goto:eof
     

    nickotron

    MP Donator
  • Premium Supporter
  • March 3, 2008
    34
    2
    Home Country
    New Zealand New Zealand
    Doing some reading in preparation for setting this up. Thanks for tips here.

    Re TommySharp/Statts's observation... yes, I see MP instantly remove it from the DB/UI when the file disappears. But isn't the solution to simply copy (not delete) the file; then move the DB pointer; then delete the old file. I haven't tried it but I would expect MP would no longer be interested in that old file being deleted, given its now looking at the new one instead.

    But... if that's true how does batsi's code work, since its doing a move, not a copy+delete? Presumably by some good fortune, the mysql gets executed before MPServer has responded to the file move notification.

    Thoughts?
     

    Users who are viewing this thread

    Top Bottom