Resetting Event Number??

Support and queries relating to all previous versions of ZoneMinder
Locked
Verbatim
Posts: 8
Joined: Mon May 04, 2009 11:17 am
Location: Cambridge, UK

Resetting Event Number??

Post by Verbatim »

Hello,

How would I reset the event count back down to 0? Or any number for that matter?

Thanks,

Alison
Debian 5.0 Lenny (no GUI) ('Standard' Installation Only, No Extras)
P4HT-3.0Ghz, 2GB RAM
Logitech QuickCam E3500 (remote)
foreverg
Posts: 25
Joined: Fri Jul 04, 2008 4:16 pm

Post by foreverg »

delete all the events thel empty the mysql Events table ;)
zappbrannigan
Posts: 7
Joined: Thu Jun 11, 2009 3:20 am

Resetting Event Number??

Post by zappbrannigan »

I too am interested in doing this.

When you say "delete all events", I would do this through the web interface, correct?

Could you elaborate on clearing the mysql events table? (I have zero experience w/ mysql).

Also, even if you do these things you're still left with the images right? Can I simply rm these images w/o causing any problems?

thanks,
eric
User avatar
cordel
Posts: 5210
Joined: Fri Mar 05, 2004 4:47 pm
Location: /USA/Washington/Seattle

Re: Resetting Event Number??

Post by cordel »

zappbrannigan wrote:I too am interested in doing this.

When you say "delete all events", I would do this through the web interface, correct?

Could you elaborate on clearing the mysql events table? (I have zero experience w/ mysql).

Also, even if you do these things you're still left with the images right? Can I simply rm these images w/o causing any problems?

thanks,
eric
No you lose all the events by dumping the table.
The event ID's are tracked by the database using the auto increment setting. If there is ever a duplicate the SQL DB would fall flat on its face. So there is no way to retain data and reset the count.
zappbrannigan
Posts: 7
Joined: Thu Jun 11, 2009 3:20 am

Re: Resetting Event Number??

Post by zappbrannigan »

If the images are deleted, that's okay.

The question still stands, how do I zero the event count?

TIA,
eric
User avatar
cordel
Posts: 5210
Joined: Fri Mar 05, 2004 4:47 pm
Location: /USA/Washington/Seattle

Post by cordel »

Drop and recreate the events table.
Assuming your db is named ZM:

The necessary disclaimer:

You are about to remove and forever lose your events. This may or may not work for you. No one can be held accountable should you follow these instructions. It is up to you to determine how your system is configured and the appropriate syntax to accommodate that configuration.

With that being said, this should work unless you have done something weird and also assumes you have named the database "zm";

Code: Select all

# /etc/init.d/zoneminder stop
# mysqldump -d zm Events > events_table.sql
# mysql zm
mysql> DROP TABLE Events;
mysql> exit
# mysql zm < events_table.sql
# /etc/init.d/zoneminder start
There are a few assumptions made but this is the basics of it. It might vary a bit according to your distro but not by much.
zappbrannigan
Posts: 7
Joined: Thu Jun 11, 2009 3:20 am

Re: Resetting Event Number??

Post by zappbrannigan »

Well, nothing seems to have been broken, however...

It did purge all the image files which I did expect but the ID number wasn't reset. (If you're in "record" mode and you open a watch window there's a list of events each with an ID number. I was hoping to reset that number but no such luck.)

Any ideas?

TIA,
eric

BTW, for my or anyone else's future reference, the idea of the previous code snippet is: make a backup of zm's Events table, but without the table's data. Then from within mysql, delete the Events table, then restore the previously backed up, now empty, table.
User avatar
cordel
Posts: 5210
Joined: Fri Mar 05, 2004 4:47 pm
Location: /USA/Washington/Seattle

Post by cordel »

Okay wasn't sure if the auto numbering would carry over, seems that it does so you will need to add an instruction before exiting mysql and starting ZM:

Code: Select all

ALTER TABLE Events AUTO_INCREMENT = 1; 
Alternatively, you can also use truncate table as it will reset the auto increment number as well.
http://dev.mysql.com/doc/refman/5.0/en/truncate.html
zappbrannigan
Posts: 7
Joined: Thu Jun 11, 2009 3:20 am

Post by zappbrannigan »

cordel wrote: Alternatively, you can also use truncate table as it will reset the auto increment number as well.
http://dev.mysql.com/doc/refman/5.0/en/truncate.html
Well, that seems to have done it. Thanks.

Just to tie everything up nice and neat:

Code: Select all

# /etc/init.d/zoneminder stop
# mysql zm
mysql> TRUNCATE TABLE Events;
mysql> exit
# /etc/init.d/zoneminder start
It looks like the mysqldump and the restoring of the dump file are
not necessary. Is that correct?

Thanks again,
eric
User avatar
cordel
Posts: 5210
Joined: Fri Mar 05, 2004 4:47 pm
Location: /USA/Washington/Seattle

Post by cordel »

You would still likely need to dump the events. Mysql I believe will pick up from the highest ID in the table, if it does not, then you risk it creating a conflict that would bring down the table and the server.

If you have the inclination to test it out, by all means please do as I would be interested myself.
psyhomb
Posts: 3
Joined: Sat Dec 05, 2009 3:32 am

Post by psyhomb »

zappbrannigan wrote:
cordel wrote: Alternatively, you can also use truncate table as it will reset the auto increment number as well.
http://dev.mysql.com/doc/refman/5.0/en/truncate.html
Well, that seems to have done it. Thanks.

Just to tie everything up nice and neat:

Code: Select all

# /etc/init.d/zoneminder stop
# mysql zm
mysql> TRUNCATE TABLE Events;
mysql> exit
# /etc/init.d/zoneminder start
It looks like the mysqldump and the restoring of the dump file are
not necessary. Is that correct?

Thanks again,
eric
Is this working without any negative consequences?
zappbrannigan
Posts: 7
Joined: Thu Jun 11, 2009 3:20 am

Post by zappbrannigan »

psyhomb wrote:
zappbrannigan wrote:
cordel wrote: Alternatively, you can also use truncate table as it will reset the auto increment number as well.
http://dev.mysql.com/doc/refman/5.0/en/truncate.html
Well, that seems to have done it. Thanks.

Just to tie everything up nice and neat:

Code: Select all

# /etc/init.d/zoneminder stop
# mysql zm
mysql> TRUNCATE TABLE Events;
mysql> exit
# /etc/init.d/zoneminder start
It looks like the mysqldump and the restoring of the dump file are
not necessary. Is that correct?

Thanks again,
eric
Is this working without any negative consequences?
I just tried it, seems to have worked fine.
Jason_Bassett
Posts: 42
Joined: Wed Mar 05, 2008 10:33 pm
Location: Stanford-Le-Hope, Thurrock, Essex

I second that

Post by Jason_Bassett »

Seems to be working fine on my test systems too. Will soon invoke it on my live ones.

J
Corrilan IT Consultancy Ltd
http://www.corrilan.com
01375 403508
enquiries@corrilan.com
PacoLM
Posts: 971
Joined: Wed Dec 02, 2009 9:55 pm
Location: Spain

Post by PacoLM »

Good trick!
masam
Posts: 1
Joined: Tue Feb 15, 2011 2:20 am
Location: there

possible Daily Honor Points...i mean....clean up script....

Post by masam »

so, what if we put the code into a shell script and run it as a crontab job, say, at midnight?!?!

(begin code)
!#/bin/bash/
echo "TRUNCATE TABLE Events;" > /home/USERNAME/zmsql.sql
/etc/init.d/zoneminder stop
mysql -uROOT -pPASSWORD use zm << zmsql.sql
/etc/init.d/zoneminder start
(end code)

then set up a crontab that uses this?
hope this helps....
Locked