how to avoid re-installation DB error

Forum for questions and support relating to the 1.24.x releases only.
Locked
carteriii
Posts: 65
Joined: Sun Oct 28, 2007 3:13 pm

how to avoid re-installation DB error

Post 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.
User avatar
cordel
Posts: 5210
Joined: Fri Mar 05, 2004 4:47 pm
Location: /USA/Washington/Seattle

Post 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.
mtgstuber
Posts: 4
Joined: Tue Dec 29, 2009 5:49 pm

Post 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.
mtgstuber
Posts: 4
Joined: Tue Dec 29, 2009 5:49 pm

Post 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.
Last edited by mtgstuber on Tue Dec 29, 2009 6:35 pm, edited 1 time in total.
mtgstuber
Posts: 4
Joined: Tue Dec 29, 2009 5:49 pm

Post 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.
coke
Posts: 518
Joined: Wed Jan 30, 2008 5:53 pm
Location: St. Louis, MO, USA

Post by coke »

You should be able to edit it at least, and then pastebin the code.
mtgstuber
Posts: 4
Joined: Tue Dec 29, 2009 5:49 pm

Post by mtgstuber »

Thanks. You're quite right. The edit button had slid off the side the screen and I missed it.
carteriii
Posts: 65
Joined: Sun Oct 28, 2007 3:13 pm

Post 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()?
carteriii
Posts: 65
Joined: Sun Oct 28, 2007 3:13 pm

Post 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.
Locked