Page 1 of 1

how to avoid re-installation DB error

Posted: Thu Dec 24, 2009 9:35 pm
by carteriii
I've had zm 1.24.2 installed & running for quite some time. I upgraded from Ubuntu 9.04 to 9.10 and for some reason it removed my zm installation. OK, so I re-ran the .deb and everything about zm works again HOWEVER...

The installation process failed at the end with the error:

Can't find upgrade from version '1.24.2' at /usr/bin/zmupdate.pl line 889

I'm looking at the source and it's easy to see why that is occurring (my DB is already at the latest version), but I'm not sure what to do about it. At a minimum I'd like to prevent zm from continuing to try to run the DB update each time I install anything else, but it also seems like the code should gracefully handle the situation when the database is already up to date.

How can I finish out this installation, and does it sound reasonable that the zmupdate.pl shouldn't fail if the DB is already of the proper version?

Thanks in advance.

Posted: Fri Dec 25, 2009 6:54 am
by cordel
It should gracefully exit already. I have done similar a few times with 1.24.2 without issue though not on ubuntu which would be the only known difference at this point.

Posted: Tue Dec 29, 2009 6:05 pm
by mtgstuber
It doesn't. :(

Unfortunately, the upgrade process from 8.04 -> 9.04 -> 9.10 removes the older installation of ZoneMinder (1.23.3), BUT, the new installation believes it's still there. As a result, the installation fails. Because of the failed installation, every time you install a new package via apt-get, synaptic, or whatever, it attempts to finish the failed installed and spawns an error.

This all having been said, I solved the problem on my machine. It was a little more hassle than I wanted, but it works.

First, grab the 1.23.3 package off zoneminder.com. Download it and configure it. You don't need to actually build it, compile it, or install it, just configure it. (Regrettably this does mean you'll need all the development dependencies in place.) From there:

Now drop the old database -- note: this removes all your data. This was fine with me because Ubuntu had already nuked my installation.

Code: Select all

$ sudo mysql -u root -p 
mysql> drop database zm;
Next, go into the 1.23.3 source tree and create a 1.23.3 database:

Code: Select all

$ cd Zoneminder-1.23.3/db
$ sudo mysql -u root -p <zm_create> grant select,insert,update,delete on zm.* to 'zmuser'@localhost identified by 'zmpass';
mysql> flush privileges;
mysql> quit;
At this point you've got an empty, old database. Now all you have to do is finish the installation of the 1.24.2 package. Assuming you already have a failed installation, all you need to do is:

Code: Select all

$ sudo apt-get -f install
It will finish installing 1.24.2 correctly.

Posted: Tue Dec 29, 2009 6:10 pm
by mtgstuber
If there is some wizard out there that has a better way to convince the 1.24.2 package to play nicely, please let me know. The above worked for me, but I fully admit it's not the elegant approach.

I had attempt to to paste the zm_create.sql file from 1.23.3 below, but it's too long. Sorry.

Posted: Tue Dec 29, 2009 6:11 pm
by mtgstuber
Nevermind. Looks like the forum won't take a post that long. Please disregard the previous post. I'd delete it, but it doesn't seem I have the privileges to do so.

Posted: Tue Dec 29, 2009 6:24 pm
by coke
You should be able to edit it at least, and then pastebin the code.

Posted: Tue Dec 29, 2009 6:35 pm
by mtgstuber
Thanks. You're quite right. The edit button had slid off the side the screen and I missed it.

Posted: Sun Jan 10, 2010 12:55 am
by carteriii
cordel wrote:It should gracefully exit already. I have done similar a few times with 1.24.2 without issue though not on ubuntu which would be the only known difference at this point.
I'm back to figuring out what is going on that prompted me to start this thread. I'm looking at the zmupdate.pl source, and I don't understand how it could gracefully exit for you. Perhaps the issue is simply that Ubuntu doesn't let the install "die()" and other distributions do, but I believe in reading the code that at a minimum, zmupdate.pl doesn't exit gracefully.

It appears that each of the blocks of code for each version end with

Code: Select all

$cascade = !undef;
There isn't a block of code for 1.24.2, so the code then enters the else block of

Code: Select all

 if ( $cascade )
    {
        my $installed_version = ZM_VERSION;
        my $sql = "update Config set Value = ? where Name = ?";
        my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
        my $res = $sth->execute( "$installed_version", "ZM_DYN_DB_VERSION" ) or die( "Can't execute: ".$sth->errstr() );
        $res = $sth->execute( "$installed_version", "ZM_DYN_CURR_VERSION" ) or die( "Can't execute: ".$sth->errstr() );
        $dbh->disconnect();
    }
    else
    {
        $dbh->disconnect();
        die( "Can't find upgrade from version '$version'" );
    }
It seems that this code really should have a block for the current version which if nothing else just does

Code: Select all

if ( $cascade || $version eq "1.24.2" )
    {
        # Do nothing, but don't die
        $cascade = !undef;
    }
Does that sound reasonable, that zmupdate.pl shouldn't ever die()?

Posted: Sat Feb 13, 2010 2:56 pm
by carteriii
Does my code change make sense? I've been running it since I made the previous post and everything works fine. This feels like a possibility to make its way into a future update to help others so I don't want to just let it pass without one of you at least getting a chance to take a look.