zmeventdump

If you've made a patch to quick fix a bug or to add a new feature not yet in the main tree then post it here so others can try it out.
Post Reply
User avatar
rdmelin
Posts: 863
Joined: Wed Oct 29, 2003 2:23 pm
Location: Ellensburg, WA USA

zmeventdump

Post by rdmelin »

This is a script that can be run from a zm filter. It uses mysqldump to create a .sql file in each filtered event directory. This will make reloading the Events table possible in the case of a corrupt or otherwise lost database.

To use this, create a filter for events you would like to "insure" with this, and save it, selecting the "Automatically execute command on all matches:" option. Use the full path to wherever you save the script.

Note: I believe only one "execute command" filter can be run on any event.

I will post a recovery utility to use with this shortly

Code: Select all

#!/bin/bash
#===============================================================================
#
#         FILE:  zmeventdump
#
#        USAGE:  ./zmeventdump <MonitorName>/<EventId>
#
#  DESCRIPTION:  Uses mysqldump to create a .sql file for individual zm
#                events to make Event table recovery possible by doing a
#                'find' search in ZoneMinder the events directory
#
#      OPTIONS:  ---  None
# REQUIREMENTS:  ---  mysqldump
#         BUGS:  ---
#        NOTES:  ---
#       AUTHOR:   Ross Melin <rdmelin@yahoo.com>
#      COMPANY:
#      VERSION:  1.0
#      CREATED:  05/20/2006 06:14:59 PM PDT
#     REVISION:  ---
#===============================================================================

# Edit these to suit your configuration
ZM_CONFIG=/etc/zm.conf
EVENTS_DIR=/var/www/html/zm/events

# The rest should not need editing
EVENT_PATH=$1
EVENT_ID=$(echo $1 |cut -f 2 -d / )

# Get the mysql user and password
source $ZM_CONFIG

# Dump the sql statements needed to reload the Events table

/usr/bin/mysqldump              \
        --user=$ZM_DB_USER      \
        --password=$ZM_DB_PASS  \
        --skip-opt              \
        --compact               \
        --quick                 \
        --no-create-info        \
        --where="Id=$EVENT_ID"  \
        zm Events >             \
        $EVENTS_DIR/$EVENT_PATH/.sql

exit 0
User avatar
zoneminder
Site Admin
Posts: 5215
Joined: Wed Jul 09, 2003 2:07 pm
Location: Bristol, UK
Contact:

Post by zoneminder »

Thanks for this Ross. I think you probably will need to dump the Frames table for the event in questions to ensure that the event is fully useable when reloaded, unless you just want the summary information that is.
Phil
User avatar
rdmelin
Posts: 863
Joined: Wed Oct 29, 2003 2:23 pm
Location: Ellensburg, WA USA

Post by rdmelin »

OK, yes I want the recovered events to be fully usable. What about the Stats table? Should I include that as well?

This will be a temporary solution if you include this feature in future releases, but it should work with some previous versions so I might as well complete it.
User avatar
zoneminder
Site Admin
Posts: 5215
Joined: Wed Jul 09, 2003 2:07 pm
Location: Bristol, UK
Contact:

Post by zoneminder »

The Stats table is not necessary unless you want to historical review the alarm %ges etc.
Phil
User avatar
rdmelin
Posts: 863
Joined: Wed Oct 29, 2003 2:23 pm
Location: Ellensburg, WA USA

Post by rdmelin »

OK heres a revised version that should get "everything"

Code: Select all

#!/bin/bash
#===============================================================================
#
#         FILE:  zmeventdump
#
#        USAGE:  ./zmeventdump <MonitorName>/<EventId>
#
#  DESCRIPTION:  Uses mysqldump to create a .sql file for individual zm
#                events to make Event table recovery possible by doing a
#                'find' search in ZoneMinder the events directory
#
#      OPTIONS:  ---  None
# REQUIREMENTS:  ---  mysqldump
#         BUGS:  ---
#        NOTES:  ---
#       AUTHOR:   Ross Melin <rdmelin@yahoo.com>
#      COMPANY:
#      VERSION:  2.0
#      CREATED:  05/26/2006 06:21:00 AM PDT
#     REVISION:  ---
#===============================================================================

# Edit these to suit your configuration
ZM_CONFIG=/etc/zm.conf
EVENTS_DIR=/var/www/html/zm/events
MYSQLDUMP=/usr/bin/mysqldump
# The rest should not need editing

# Get the mysql user and password
source $ZM_CONFIG

EVENT_PATH=$1
EVENT_ID=$(echo $1 |cut -f 2 -d / )
MYDUMPOPTS="--user=$ZM_DB_USER --password=$ZM_DB_PASS --skip-opt --compact --quick --no-create-info"

# Dump the sql statements needed to reload the Events, Frames and Stats tables
$MYSQLDUMP $MYDUMPOPTS --where="Id=$EVENT_ID" zm Events > $EVENTS_DIR/$EVENT_PATH/.sql
$MYSQLDUMP $MYDUMPOPTS --where="Eventid=$EVENT_ID" zm Frames >> $EVENTS_DIR/$EVENT_PATH/.sql
$MYSQLDUMP $MYDUMPOPTS --where="Eventid=$EVENT_ID" zm Stats >> $EVENTS_DIR/$EVENT_PATH/.sql

exit 0
Post Reply