Power failure: Zoneminder won't start

Forum for questions and support relating to the 1.25.x releases only.
Locked
codeking2011
Posts: 2
Joined: Fri May 10, 2013 2:37 pm

Power failure: Zoneminder won't start

Post by codeking2011 »

Hello all,

We had a power failure and the ZoneMinder server was improperly shut down. After I have restarted it again I got the following error: -

#service zm status
httpd (pid 1858 1857 1856 1855 1854 1853 1852 1851 1850 1833) is running...
mysqld (pid 1719) is running...
DBD::mysql::st execute failed: Table './zm/Logs' is marked as crashed and should be repaired at /usr/local/share/perl5/ZoneMinder/Logger.pm line 609.

While I tried to http the server I got another error: -

Can't write log entry 'insert into Logs ( TimeKey, Component, Pid, Level, Code, Message, File, Line ) values ( 1368195917.303554, 'web_php', 1856, -3, 'FAT', 'SQL-ERR \'Table \'./zm/Logs\' is marked as crashed and should be repaired\', statement was \'select Level, count(Level) as LevelCount from Logs where Level < 0 and from_unixtime(TimeKey) + interval 900 second > now() group by Level order by Level asc\'', '/home/www/html/zm/includes/database.php', 78 )': Table './zm/Logs' is marked as crashed and should be repaired

In Logs

May 10 15:59:32 Video zmpkg[2105]: FAT [Can't execute log entry 'insert into Logs ( TimeKey, Component, Pid, Level, Code, Message, File, Line ) values ( ?, ?, ?, ?, ?, ?, ?, NULL )': Table './zm/Logs' is marked as crashed and should be repaired]

May 10 16:16:46 Video web_php[1853]: FAT [SQL-ERR 'Table './zm/Logs' is marked as crashed and should be repaired', statement was 'select Level, count(Level) as LevelCount from Logs where Level < 0 and from_unixtime(TimeKey) + interval 900 second > now() group by Level order by Level asc']
May 10 16:16:46 Video web_php[1853]: FAT [Can't write log entry 'insert into Logs ( TimeKey, Component, Pid, Level, Code, Message, File, Line ) values ( 1368195406.295318, 'web_php', 1853, -3, 'FAT', 'SQL-ERR \'Table \'./zm/Logs\' is marked as crashed and should be repaired\', statement was \'select Level, count(Level) as LevelCount from Logs where Level < 0 and from_unixtime(TimeKey) + interval 900 second > now() group by Level order by Level asc\'', '/home/www/html/zm/includes/database.php', 78 )': Table './zm/Logs' is marked as crashed and should be repaired]
May 10 16:17:22 Video zmpkg[2180]: FAT [Can't execute log entry 'insert into Logs ( TimeKey, Component, Pid, Level, Code, Message, File, Line ) values ( ?, ?, ?, ?, ?, ?, ?, NULL )': Table './zm/Logs' is marked as crashed and should be repaired]
May 10 16:17:23 Video web_php[1855]: FAT [SQL-ERR 'Table './zm/Logs' is marked as crashed and should be repaired', statement was 'select Level, count(Level) as LevelCount from Logs where Level < 0 and from_unixtime(TimeKey) + interval 900 second > now() group by Level order by Level asc']
May 10 16:17:23 Video web_php[1855]: FAT [Can't write log entry 'insert into Logs ( TimeKey, Component, Pid, Level, Code, Message, File, Line ) values ( 1368195443.018944, 'web_php', 1855, -3, 'FAT', 'SQL-ERR \'Table \'./zm/Logs\' is marked as crashed and should be repaired\', statement was \'select Level, count(Level) as LevelCount from Logs where Level < 0 and from_unixtime(TimeKey) + interval 900 second > now() group by Level order by Level asc\'', '/home/www/html/zm/includes/database.php', 78 )': Table './zm/Logs' is marked as crashed and should be repaired]


How can I repair this issue??
Any advice/help would be appreciated
Thanks
Last edited by codeking2011 on Fri May 10, 2013 3:29 pm, edited 1 time in total.
codeking2011
Posts: 2
Joined: Fri May 10, 2013 2:37 pm

Re: Power failure: Zoneminder won't start

Post by codeking2011 »

Thanks alot bb99 it works like a magic :)
sys_adm78
Posts: 1
Joined: Tue Aug 09, 2016 6:55 pm

Re: Power failure: Zoneminder won't start

Post by sys_adm78 »

Hi I am having the same issue
#service zm status
httpd (pid 1858 1857 1856 1855 1854 1853 1852 1851 1850 1833) is running...
mysqld (pid 1719) is running...
DBD::mysql::st execute failed: Table './zm/Logs' is marked as crashed and should be repaired at /usr/local/share/perl5/ZoneMinder/Logger.pm line 609.

Do you remember how you fixed yours?

codeking2011 wrote:Hello all,

We had a power failure and the ZoneMinder server was improperly shut down. After I have restarted it again I got the following error: -

#service zm status
httpd (pid 1858 1857 1856 1855 1854 1853 1852 1851 1850 1833) is running...
mysqld (pid 1719) is running...
DBD::mysql::st execute failed: Table './zm/Logs' is marked as crashed and should be repaired at /usr/local/share/perl5/ZoneMinder/Logger.pm line 609.

While I tried to http the server I got another error: -

Can't write log entry 'insert into Logs ( TimeKey, Component, Pid, Level, Code, Message, File, Line ) values ( 1368195917.303554, 'web_php', 1856, -3, 'FAT', 'SQL-ERR \'Table \'./zm/Logs\' is marked as crashed and should be repaired\', statement was \'select Level, count(Level) as LevelCount from Logs where Level < 0 and from_unixtime(TimeKey) + interval 900 second > now() group by Level order by Level asc\'', '/home/www/html/zm/includes/database.php', 78 )': Table './zm/Logs' is marked as crashed and should be repaired

In Logs

May 10 15:59:32 Video zmpkg[2105]: FAT [Can't execute log entry 'insert into Logs ( TimeKey, Component, Pid, Level, Code, Message, File, Line ) values ( ?, ?, ?, ?, ?, ?, ?, NULL )': Table './zm/Logs' is marked as crashed and should be repaired]

May 10 16:16:46 Video web_php[1853]: FAT [SQL-ERR 'Table './zm/Logs' is marked as crashed and should be repaired', statement was 'select Level, count(Level) as LevelCount from Logs where Level < 0 and from_unixtime(TimeKey) + interval 900 second > now() group by Level order by Level asc']
May 10 16:16:46 Video web_php[1853]: FAT [Can't write log entry 'insert into Logs ( TimeKey, Component, Pid, Level, Code, Message, File, Line ) values ( 1368195406.295318, 'web_php', 1853, -3, 'FAT', 'SQL-ERR \'Table \'./zm/Logs\' is marked as crashed and should be repaired\', statement was \'select Level, count(Level) as LevelCount from Logs where Level < 0 and from_unixtime(TimeKey) + interval 900 second > now() group by Level order by Level asc\'', '/home/www/html/zm/includes/database.php', 78 )': Table './zm/Logs' is marked as crashed and should be repaired]
May 10 16:17:22 Video zmpkg[2180]: FAT [Can't execute log entry 'insert into Logs ( TimeKey, Component, Pid, Level, Code, Message, File, Line ) values ( ?, ?, ?, ?, ?, ?, ?, NULL )': Table './zm/Logs' is marked as crashed and should be repaired]
May 10 16:17:23 Video web_php[1855]: FAT [SQL-ERR 'Table './zm/Logs' is marked as crashed and should be repaired', statement was 'select Level, count(Level) as LevelCount from Logs where Level < 0 and from_unixtime(TimeKey) + interval 900 second > now() group by Level order by Level asc']
May 10 16:17:23 Video web_php[1855]: FAT [Can't write log entry 'insert into Logs ( TimeKey, Component, Pid, Level, Code, Message, File, Line ) values ( 1368195443.018944, 'web_php', 1855, -3, 'FAT', 'SQL-ERR \'Table \'./zm/Logs\' is marked as crashed and should be repaired\', statement was \'select Level, count(Level) as LevelCount from Logs where Level < 0 and from_unixtime(TimeKey) + interval 900 second > now() group by Level order by Level asc\'', '/home/www/html/zm/includes/database.php', 78 )': Table './zm/Logs' is marked as crashed and should be repaired]


How can I repair this issue??
Any advice/help would be appreciated
Thanks
DoubleHP
Posts: 18
Joined: Fri Sep 02, 2016 1:13 pm

Re: Power failure: Zoneminder won't start

Post by DoubleHP »

codeking2011 wrote:Thanks alot bb99 it works like a magic :)
Because Internet is magic, and because life shall never be easy ... the indicated page is dropped. And of course, no proper redirection have been set.

But, let's dig using spells ...

https://web.archive.org/web/20140320151 ... ex.php/FAQ

(well, the page redirects to http://zoneminder.readthedocs.io/en/latest/faq.html ... which contains invalid commands; so, it's useless)

It states:
How do I repair the MySQL Database?

There is two ways to go about this. In most cases you can run from the command prompt ->

mysqlcheck --all-databases --auto-repair -pyour_database_password -u your_databse_user

If that does not work then you will have to make sure that ZoneMinder is stopped then run the following (nothing should be using the database while running this and you will have to adjust for your correct path if it is different). ->

myisamchk --silent --force --fast --update-state -O key_buffer=64M -O sort_buffer=64M -O read_buffer=1M -O write_buffer=1M /var/lib/mysql/*/*.MYI


How do I repair the MySQL Database when the cli fails?

In Ubuntu, the commands listed above do not seem to work. However, actually doing it by hand from within MySQL does. (But that is beyond the scope of this document) But that got me thinking... And phpmyadmin does work. Bring up a terminal.

sudo apt-get install phpmyadmin

Now go to http://zoneminder_IP/ and stop the ZM service. Continue to http://zoneminder_IP/phpmyadmin and select the zoneminder database. Select and tables marked 'in use' and pick the action 'repare' to fix. Restart the zoneminder service from the web browser. Remove or disable the phpmyadmin tool, as it is not always the most secure thing around, and opens your database wide to any skilled hacker.

sudo apt-get remove phpmyadmin
Here is what it becomes for me:

Code: Select all

# cat /etc/zm/zm.conf | grep ZM_DB
ZM_DB_TYPE=mysql
ZM_DB_HOST=localhost
ZM_DB_NAME=zm
ZM_DB_USER=zmuser
ZM_DB_PASS=zmpass

# mysqlcheck --all-databases --auto-repair -pzmpass -u zmuser
Warning: Using a password on the command line interface can be insecure.
zm.Config                                          OK
zm.ControlPresets                                  OK
zm.Controls                                        OK
zm.Devices                                         OK
zm.Events                                          OK
zm.Filters                                         OK
zm.Frames                                          OK
zm.Groups                                          OK
zm.Logs                                            OK
zm.MonitorPresets                                  OK
zm.Monitors                                        OK
zm.Servers                                         OK
zm.States                                          OK
zm.Stats
Warning  : InnoDB: Index 'EventId' contains 186064 entries, should be 186095.
Warning  : InnoDB: Index 'MonitorId' contains 186064 entries, should be 186095.
Warning  : InnoDB: Index 'ZoneId' contains 186064 entries, should be 186095.
error    : Corrupt
zm.TriggersX10                                     OK
zm.Users                                           OK
zm.ZonePresets                                     OK
zm.Zones                                           OK

Repairing tables
zm.Stats
note     : The storage engine for the table doesn't support repair


# myisamchk --silent --force --fast --update-state -O key_buffer=64M -O sort_buffer=64M -O read_buffer=1M -O write_buffer=1M /var/lib/mysql/*/*.MYI
myisamchk: unknown option '-O'

(the new tuto is missing stars in the last argument).

In the end, I am stuck.

If the only way is to reset mysql completely, and loose all events and all configuration every 3 months, I really prefer using any other more expensive solution. I have spend dozens (hundreds ?) of hours trying to make ZM work. Author refuses to listen to the fact it has bugs, and all bugs have been closed within MINUTES WITHOUT FIX. He is just too proud to accept he is not god, and he may make typos.

But, having to reset the main DBs, and loose events, and monitors and zones ... that's too much for me. I will buy a high brand hardware recorder.
SteveGilvarry
Posts: 494
Joined: Sun Jun 29, 2014 1:12 pm
Location: Melbourne, AU

Re: Power failure: Zoneminder won't start

Post by SteveGilvarry »

FYI Mysql crashed tables is not a Zoneminder issue, can happen to any mysql database in sudden power loss.

Your tables are using innodb not myisam. If you search "mysql innodb table crash" you will find answers. I think I lost a Logs table and it was easier to just dump and recreate it. As I didn't have backups in place at the time and I will assume you are in the same boat.
Maybe something in this will assist you.
https://forums.cpanel.net/threads/innod ... de.418722/
Production Zoneminder 1.37.x (Living dangerously)
Random Selection of Cameras (Dahua and Hikvision)
Locked