Page 1 of 1

Failed to Initialize database

Posted: 10 Apr 2014, 14:39
by Clifford
Any idea how I might fix this? Logfile is attached, but here are the first few lines

[2014-04-10 09:28:44,410] INFO DaoHelper - Checking database schema.
[2014-04-10 09:29:39,806] ERROR DaoHelper - Failed to initialize database.
org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: File input/output error c:\madsonic/db/subsonic.backup java.io.EOFException: Unexpected end of ZLIB input stream

Re: Failed to Initialize database

Posted: 10 Apr 2014, 14:50
by Madsonic
hi there,

it looks like you have a corrupted database file, try to stop the Madsonic Service, delete the c:\madsonic\db folder (to restart DB from scratch)
and restart your service. A new Database will be created automatically.

best regards

Re: Failed to Initialize database

Posted: 10 Apr 2014, 15:11
by Clifford
Thanks, recreating now.

For future, is there any way to save/backup playlists, ratings, etc?

Re: Failed to Initialize database

Posted: 10 Apr 2014, 15:36
by GJ51
Sure - make a back up BEFORE it crashes.

Just make a regular archive copy of the C:\Madsonic directory so you have a recent backup. You can manually copy once in a while, or if you're on Windoze you can use SyncToy to make automated backups. If you do the automated route, just be sure to occasionally back up one of the backups so that the process doesn't just blindly overwrite a good backup with a new "crashed" copy.

Re: Failed to Initialize database

Posted: 10 Apr 2014, 15:48
by Clifford
Do I need to shutdown madsonic prior to the backup?

Re: Failed to Initialize database

Posted: 10 Apr 2014, 16:11
by GJ51
Probably a good idea. I'm not sure, but it makes sense to stop the service, copy, then restart.

Re: Failed to Initialize database

Posted: 10 Apr 2014, 17:45
by Clifford
Synctoy wasn't working for me, not enough control.

Here's my attempt at a backup batch file. If you're interested I can send the called batch files as well.

@echo off
set appver=1.1
:: Check for new version on the server, move it local if updated
call checkbat MadSonicBackup
echo .
echo %0 Ver 1.0
if (%debug%)==(on) set debug=on

if /i (%1)==(/w) echo Force Weekly
:: Backup Drive
set dest=R:

:: every tried to break out of process that doesn't ask for keyboard input?
set break on
:: Time the backup. A backup time that is out of whack indicates a problem
call elapsedtime /start

call Logger MadSonic Backup Started
:: Determine which day it is. Daily backups have their own folder
call dow.bat
set wkly=Sun

:: Are we forcing a weekly backup?
if /i (%1)==(/w) set wkly=%dow%
echo %wkly%

if /i (%debug%)==(on) pause

echo Backing up for %dow%
echo stopping MadSonic service
"c:\madsonic\madsonic-service.exe" -stop
echo Madsonic Service Stopped

if (%dow%)==(%wkly%) echo Backup for %dow% is Weekly (%wkly%)
if not (%dow%)==(%wkly%) echo Backup for %dow% is Daily (weekly is %wkly%)
echo .

:next1
:: Make folders if they don't exist
if not exist R:\backups\Madsonicbackup\*.* md R:\backups\Madsonicbackup
if not exist R:\backups\madsonicbackup\%computername%\*.* md R:\backups\madsonicbackup\%computername%
if not exist R:\backups\madsonicbackup\%computername%\daily\*.* md R:\backups\madsonicbackup\%computername%\daily
if not exist R:\backups\madsonicbackup\%computername%\weekly_%wkly%\*.* md R:\backups\madsonicbackup\%computername%\weekly_%wkly%

:: Variable dest is where the backups will go
set dest=R:\backups\madsonicbackup\%computername%\daily
set msg=Madsonic Backup Finished
if /i (%debug%)==(on) pause

if (%1)==(/t) set msg=TEST %msg%

if (%dow%)==(%wkly%) set dest=R:\backups\madsonicbackup\%computername%\weekly_%wkly%
if (%dow%)==(%wkly%) set msg=Madsonic Weekly Backup on %dow% Finished
if not (%dow%)==(%wkly%) echo Doing daily Backup to %dest%
if (%dow%)==(%wkly%) echo Doing Weekly Backup to %dest%

Echo Some quick Housekeeping
echo Backing up to: %dest%

echo Cleaning DB folder
if not (%dow%) == (Fri) goto noclean
del %dest%\db\*.* /s /f /q > nul
echo Cleaning Jetty Folder
del %dest%\jetty\*.* /s /f /q > nul
echo Cleaning Lucene Folder
del %dest%\lucene\*.* /s /f /q > nul
echo Cleaning Main Folder
del %dest%\*.* /f /q > nul

:noclean

set break=on
echo Copying MadSonic files to %dest%
call Logger "%msg%" %dest%
echo on
del %dest%\db\*.* /f /Q
dir c:\madsonic
echo Backing up to: %dest%, This will take a while
echo .
xcopy c:\madsonic\*.* %dest% /Y /d /s > nul


:: Clean up the Podcast folder, we don't need to keep that
del %dest%\podcasts\*.mp3 /f /Q

echo off
call elapsedtime /stop
call Logger Ended: "%msg%" %dest% " Total Elapsedtime: "%elapsed%
sleep 5

if exist %dest%\tmp*.txt del %dest%\tmp*.txt /f
:: We call Filestamp so folders will show they have been updated
call filestamp R:\backups\madsonicbackup\%computername%\


:: All good - restart
c:\madsonic\madsonic-service.exe -start

if /i (%debug%)==(on) pause

:next2
if (%1)==(/t) echo Backup to %dest%


:: We should email the log here....but we haven't yet

Re: Failed to Initialize database

Posted: 10 Apr 2014, 18:17
by GJ51
Thank you,

Nice job. Personally, I don't run into db failures very often and I run several Subsonic/Madsonic instances in parallel in multiple VM's, but your efforts here are much appreciated. This seems to be a common issue in the forums. I don't know why, other than factors that might turn the host machine off without giving the db time to close out the files properly. Could be related to drive caches not flushing prior to shutdown or something along those lines.

In any event, I'm sure that many Windows users might find this a valuable way to be prepared.

Re: Failed to Initialize database

Posted: 10 Apr 2014, 19:31
by Clifford
Thanks. BTW, I noticed a bug where I used the subfolder named ...\daily where I should have used ...\%dow%. I could have gone with son, father, grandfather, but this was easier.

I've attached the updated file here. If anyone is interested, let me know and I can supply the supporting files.