Corrupted database (1 Viewer)

de2maso

Portal Member
March 10, 2010
33
5
Home Country
Norway Norway
Hi

I need some help.

After Windows gave me a BSOD last night i'm having trouble getting Mediaportal to boot up.
I was at the time adding a new episode to My Tvseries folder.

So I have disabled Tv-series in the config, and now MP will start again.

My question is, do i uninstall, and reinstall?, do I delete some database files? or do I use Windows system restore a couple of days back.

Need logs: tell me :)

Whats the best approach ?

Thanks
 

kiwijunglist

Super Moderator
  • Team MediaPortal
  • June 10, 2008
    6,746
    1,751
    New Zealand
    Home Country
    New Zealand New Zealand
    Just delete your database or restore from backup.


    So when I had this problem MP wouldn't start, it took me 1 hour to figure out it was a corrupted database in tv series plugin. Is there a quick check that could be done by tv series on startup that would show up more than half of the database corruption problems, and if database is corrupt then tv series skips what ever start up process that causes MP to hang, and then when you try to enter tv series it gives a window saying corrupt database?
     
    Last edited:

    RoChess

    Extension Developer
  • Premium Supporter
  • March 10, 2006
    4,434
    1,897
    Just delete your database or restore from backup.


    So when I had this problem MP wouldn't start, it took me 1 hour to figure out it was a corrupted database in tv series plugin. Is there a quick check that could be done by tv series on startup that would show up more than half of the database corruption problems, and if database is corrupt then tv series skips what ever start up process that causes MP to hang, and then when you try to enter tv series it gives a window saying corrupt database?

    I actually have a small script at home that does a quick SQLite database integrity check on all DB3 databases, and if valid it auto-backs it up (which then makes it the most recent 'good' backup), and when it fails auto-restores the last good-backup.

    Will rewrite the script to become generic for everybody, and not just specific to my own needs. The benefit is that it works on all databases then, and not just MP-TVSeries. The backup MPEI plugin might also be of use, because it also takes care of the thumbs folder if memory serves me.

    Not gonna have time this weekend, but will get to it next weekend, or before.
     

    de2maso

    Portal Member
    March 10, 2010
    33
    5
    Home Country
    Norway Norway
    Thanks for input guys

    @ RoChess that script sounds interesting to try out ! :)
     

    RoChess

    Extension Developer
  • Premium Supporter
  • March 10, 2006
    4,434
    1,897
    Finally found some time to scrub script, so here goes:

    [collapse]
    Code:
    @Echo Off
    ::
    :: Auto backup/restore MediaPortal databases based on integrity check.
    ::
    :: Author  » RoChess
    :: Updated » July 19th 2013
    ::
    SET BACKUP=AutoBackup
    SET MEPO_PATH=Team MediaPortal\MediaPortal\database
    IF EXIST "%AllUsersProfile%\Application Data\%MEPO_PATH%\*.db3" SET DB3_PATH=%AllUsersProfile%\Application Data\%MEPO_PATH%
    IF EXIST "%AllUsersProfile%\%MEPO_PATH%\*.db3"   SET DB3_PATH=%AllUsersProfile%\%MEPO_PATH%
    IF "%DB3_PATH%"=="" GOTO Error_MePo
    IF NOT EXIST "%~dp0\sqlite3.exe" GOTO Error_SQLite
    :: Check to make sure MediaPortal is not still running
    ::
    tasklist | find /i /c "MediaPortal.exe" >nul &&goto MediaPortalRunning
    tasklist | find /i /c "PluginConfigLoader.exe" >nul &&goto MediaPortalRunning
    tasklist | find /i /c "Moving Pictures Config.exe" >nul &&goto MediaPortalRunning
    tasklist | find /i /c "MP-TVSeries-Configuration.exe" >nul &&goto MediaPortalRunning
    
    echo Auto Backup/Restore STARTED (%DATE% -- %TIME%) >"%~dpn0.log"
    echo.>>"%~dpn0.log"
    CD /D "%DB3_PATH%"
    FOR %%I IN (*.db3) DO (
    CALL:checkSQLite "%%I"
    )
    echo.>>"%~dpn0.log"
    echo Auto Backup/Restore FINISHED (%DATE% -- %TIME%) >>"%~dpn0.log"
    :LaunchMediaPortal
    :: Locating MediaPortal folder
    ::
    IF EXIST "%ProgramFiles%\Team MediaPortal\MediaPortal\MediaPortal.exe"  (
      start "MediaPortal" "%ProgramFiles%\Team MediaPortal\MediaPortal\MediaPortal.exe"
    ) ELSE (
      IF EXIST "%ProgramFiles(x86)%\Team MediaPortal\MediaPortal\MediaPortal.exe"  (
       start "MediaPortal" "%ProgramFiles(x86)%\Team MediaPortal\MediaPortal\MediaPortal.exe"
      ) ELSE (
       Goto MediaPortalNotFound
      )
    )
    GOTO:EOF
    :checkSQLite
    IF %~z1 EQU 0 (
      echo    Aborting: "%~nx1" is ZERO bytes
      echo    Aborting: "%~nx1" is ZERO bytes >>"%~dpn0.log"
      GOTO:EOF
    )
    SET Pass=No
    echo PRAGMA integrity_check; | "%~dp0\sqlite3.exe" "%~dpf1" | find /c "ok" > nul &&SET Pass=Yes
    IF "%Pass%"=="Yes" (
      echo    Updating backup for: "%~nx1"
      echo    Updating backup for: "%~nx1" >>"%~dpn0.log"
      xcopy "%DB3_PATH%\%~nx1" "%DB3_PATH%\%BACKUP%\" /I /C /D /Y /Q >nul
    )
    IF "%Pass%"=="No" (
      echo    ERROR: DATABASE CORRUPT!
      IF NOT EXIST "%DB3_PATH%\%BACKUP%\%~nx1" (
       echo     - No backup exists for: "%~nx1"
       echo     - No backup exists for: "%~nx1" >>"%~dpn0.log"
      )
      IF EXIST "%DB3_PATH%\%BACKUP%\%~nx1" (
       echo     - Restoring last-known good backup for: "%~nx1"
       echo     - Restoring last-known good backup for: "%~nx1" >>"%~dpn0.log"
       xcopy "%DB3_PATH%\%BACKUP%\%~nx1" "%DB3_PATH%\" /I /C /Y /Q >nul
      )
    )
    GOTO:EOF
    :MediaPortalRunning
    echo   WARNING: MediaPortal is still running!!
    echo.
    echo     MediaPortal and/or Configuration tools are still active.
    echo     Try it again later, after giving it more time to finish.
    GOTO ErrorDelay
    :MediaPortalNotFound
    echo   WARNING: MediaPortal *NOT* Found!!
    echo.
    echo     Unable to locate MediaPortal in the default location.
    echo     Please adjust this script manually to use your custom folder.
    goto ErrorDelay
    :Error_MePo
    echo   ABORTING: MediaPortal databases not found
    echo.
    echo     Nothing to do, please verify your MediaPortal installation.
    GOTO ErrorDelay
    :Error_SQLite
    echo   ABORTING: SQLite.exe command-line tool missing!
    echo.
    echo     Download binary shell for Windows from: [URL]http://www.sqlite.org/download.html[/URL]
    echo     Unzip and copy sqlite3.exe to:
    echo.
    echo         "%~dp0"
    GOTO ErrorDelay
    :ErrorDelay
    echo.
    echo   This window will self-destruct in a few seconds.
    echo.
    ping 1.1 -n 1 -w 5000 >nul
    GOTO:EOF
    [/collapse]

    To make it easier, I've attached script+sqlite3.exe in a ZIP file.

    Function:

    - It will use sqlite3.exe tool to verify all the DB3 databases did not go corrupt.
    - If DB3 passes check, it will make a fresh backup.
    - If check fails, it will auto-recover last-known good backup.
    - After it backed-up/restored all the databases, it will launch MediaPortal (it also does a check to make sure MePo is not running)

    Use this script to replace the method in which you normally launch MediaPortal.
     

    Attachments

    • AutoBackup.zip
      249 KB

    de2maso

    Portal Member
    March 10, 2010
    33
    5
    Home Country
    Norway Norway
    @RoChess: Sorry for a late reply, been away on holiday.

    This looks amazing just tried it out, and seems to work well, i got a autobackup log file. Thank you so much!!

    Just to verify I understand everything correctly : Do you actually use the Atuobackup.cmd to start MP everytime ?

    See i got some keymapping going on my keyboard, so I need todo some remapping if that is the case.

    Again : great work! :)
     

    RoChess

    Extension Developer
  • Premium Supporter
  • March 10, 2006
    4,434
    1,897
    @RoChess: Sorry for a late reply, been away on holiday.

    This looks amazing just tried it out, and seems to work well, i got a autobackup log file. Thank you so much!!

    Just to verify I understand everything correctly : Do you actually use the Atuobackup.cmd to start MP everytime ?

    See i got some keymapping going on my keyboard, so I need todo some remapping if that is the case.

    Again : great work! :)

    I use a slightly modified version that also checks if RDP is active, and I have that script in my 'startup' folder so when the computer boots, it launches MediaPortal (and does the auto-backup/restore), but then on my ATi Remote Wonder, the 'A' button at the top next to the Power-Off button to shut down MediaPortal allows me to re-activate it. Then inside Windows I changed the CMD display to be "Lucida console" font size 20, white background with black text. That way it doesn't look horrible for me as I like a 'bright' environment.

    The existing script verifies if any MediaPortal related item (the ones I'm aware off) is already running and prevents it from running again. So if I accidently click the 'A button while MePo is already running, the CMD window will show ontop and auto-dissapears after a while with the error message to not start it again.

    Sometimes MediaPortal takes longer then usually to 'stop' as well when I close it, so the same method prevents dbase corruption from occuring then, and the script will fix it if it does happen.
     

    Users who are viewing this thread

    Top Bottom