Bug 461 - Added RDM scripts.
git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@2299 e3e1d417-86f3-4887-817a-d78f3d33393f
This commit is contained in:
parent
569b669a9e
commit
12dbabe916
|
@ -0,0 +1,37 @@
|
|||
#!/bin/bash
|
||||
#===============================================================================
|
||||
#
|
||||
# FILE: zmdbbackup
|
||||
#
|
||||
# USAGE: ./zmdbbackup
|
||||
#
|
||||
# DESCRIPTION: Uses mysqldump to backup the config info in the zm DB
|
||||
# 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=@ZM_CONFIG@
|
||||
source $ZM_CONFIG
|
||||
|
||||
MYSQLDUMP=/usr/bin/mysqldump
|
||||
BACKUP_PATH=/var/lib/zm
|
||||
BACKUP_FILE=zm_backup.sql
|
||||
DUMPOPTS="--user=$ZM_DB_USER --password=$ZM_DB_PASS --opt"
|
||||
TABLES="Config Filters Groups Monitors States TriggersX10 Users Zones"
|
||||
OUTFILE="$BACKUP_PATH/$BACKUP_FILE"
|
||||
|
||||
echo "--
|
||||
--- Created by zm_db_backup for ZoneMinder Version $ZM_VERSION
|
||||
--" > $OUTFILE
|
||||
|
||||
$MYSQLDUMP $DUMPOPTS zm $TABLES >> $OUTFILE
|
||||
|
||||
exit 0
|
|
@ -0,0 +1,172 @@
|
|||
#!/bin/bash
|
||||
#===============================================================================
|
||||
#
|
||||
# FILE: zmdbrestore
|
||||
#
|
||||
# USAGE: ./zmdbrestore
|
||||
#
|
||||
# DESCRIPTION: Restore a ZoneMinder DB from a backup created by zm_db_backup
|
||||
#
|
||||
# OPTIONS: ---
|
||||
# REQUIREMENTS: ---
|
||||
# BUGS: ---
|
||||
# NOTES: ---
|
||||
# AUTHOR: (),
|
||||
# COMPANY:
|
||||
# VERSION: 1.0
|
||||
# CREATED: 05/29/2006 04:45:06 PM PDT
|
||||
# REVISION: ---
|
||||
#===============================================================================
|
||||
|
||||
ZM_CONFIG=@ZM_CONFIG@
|
||||
ZM_BACKUP=/var/lib/zm/zm_backup.sql
|
||||
EVENTS_DIR=events
|
||||
|
||||
loadcfg() {
|
||||
if [ -f $ZM_CONFIG ]; then
|
||||
. $ZM_CONFIG
|
||||
else
|
||||
echo "ERROR: $ZM_CONFIG not found."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
chkcfg(){
|
||||
for n in ZM_DB_HOST ZM_DB_NAME ZM_DB_USER ZM_DB_PASS; do
|
||||
eval "val=\$$n"
|
||||
if [ "$val" = "" ]; then
|
||||
echo "ERROR($ZM_CONFIG): $n should not be empty."
|
||||
echo "Enter a $n for ZM to use the Database."
|
||||
if [ "$n" = "ZM_DB_PASS" ]; then
|
||||
echo -n "Will not echo on screen $n : "
|
||||
stty -echo # Turns off screen echo.
|
||||
read newval
|
||||
stty echo # Restores screen echo.
|
||||
echo ""
|
||||
### The following can be used to generate a random password
|
||||
# randstr newval 16
|
||||
else
|
||||
echo -n "$n : "
|
||||
read newval
|
||||
fi
|
||||
cp $ZM_CONFIG /tmp/$$ &&
|
||||
sed 's/^'$n='.*$/'$n=$newval'/g' /tmp/$$ >$ZM_CONFIG
|
||||
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$ZM_DB_HOST" = "localhost" ]
|
||||
then
|
||||
ClientHost=localhost
|
||||
else
|
||||
ClientHost=`hostname`
|
||||
fi
|
||||
}
|
||||
|
||||
reloadcfg(){
|
||||
loadcfg
|
||||
}
|
||||
|
||||
chk_backup_ver(){
|
||||
if
|
||||
[ -e $ZM_BACKUP ]
|
||||
then
|
||||
BACKUP_VER=$(cat $ZM_BACKUP | head -n 2 |tail -n 1 |cut -f 8 -d " ")
|
||||
else
|
||||
echo "$ZM_BACKUP doesn't exist"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
if
|
||||
[ $BACKUP_VER != $ZM_VERSION ]
|
||||
then
|
||||
echo "$ZM_BACKUP is from version $BACKUP_VER"
|
||||
echo "ZoneMinder version is $ZM_VERSION"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
getmylogin(){
|
||||
echo "Enter MySQL Administrator username"
|
||||
echo "(Default: root and password is blank)"
|
||||
echo -n "MySQL Admin: "
|
||||
read MYADMIN
|
||||
echo -n "Password: "
|
||||
read MYPASS
|
||||
if [ "X$MYPASS" != "X" ]; then MYPASS="-p$MYPASS"; fi
|
||||
echo "\q" |mysql -u $MYADMIN $MYPASS || exit 0
|
||||
|
||||
}
|
||||
|
||||
checkfordb(){
|
||||
|
||||
if
|
||||
echo "show databases" |mysql -u $MYADMIN "$MYPASS" |grep zm
|
||||
then
|
||||
echo "A $ZM_DB_NAME database exists."
|
||||
while [ true ]
|
||||
do
|
||||
echo "Choose one of the following options:"
|
||||
echo "[D]rop the old database and reinitialize"
|
||||
echo "[E]xit and do nothing"
|
||||
read OPTION
|
||||
case $OPTION in
|
||||
"D"|"d")
|
||||
echo "drop database zm;"|mysql -u $MYADMIN $MYPASS
|
||||
return
|
||||
;;
|
||||
"E"|"e")
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
fi
|
||||
}
|
||||
|
||||
initdb(){
|
||||
sql=/tmp/zm.crdb.sql
|
||||
echo "" >$sql
|
||||
chmod 600 $sql
|
||||
|
||||
echo "CREATE DATABASE $ZM_DB_NAME;" >>$sql
|
||||
echo "USE $ZM_DB_NAME;" >>$sql
|
||||
|
||||
echo "GRANT all on $ZM_DB_NAME.* TO '$ZM_DB_USER'@'$ClientHost' IDENTIFIED BY '$ZM_DB_PASS';" >>$sql
|
||||
|
||||
cat $sql | mysql -B -h $ZM_DB_HOST -u $MYADMIN $MYPASS
|
||||
rm -f $sql
|
||||
|
||||
cat $ZM_PATH_UPDATE/zm_create.sql | mysql -h $ZM_DB_HOST -u $ZM_DB_USER -p$ZM_DB_PASS $ZM_DB_NAME
|
||||
|
||||
}
|
||||
|
||||
restoredb(){
|
||||
if
|
||||
[ -e $ZM_BACKUP ]
|
||||
then
|
||||
cat $ZM_BACKUP | mysql -h $ZM_DB_HOST -u $ZM_DB_USER -p$ZM_DB_PASS $ZM_DB_NAME
|
||||
else
|
||||
echo "$ZM_BACKUP doesn't exist"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
restore_events(){
|
||||
for SQL in $(find $ZM_PATH_WEB/$EVENTS_DIR -name .sql)
|
||||
do
|
||||
cat $SQL | mysql -h $ZM_DB_HOST -u $ZM_DB_USER -p$ZM_DB_PASS $ZM_DB_NAME
|
||||
done
|
||||
}
|
||||
|
||||
loadcfg
|
||||
chkcfg
|
||||
reloadcfg
|
||||
chk_backup_ver
|
||||
getmylogin
|
||||
checkfordb
|
||||
initdb
|
||||
restoredb
|
||||
restore_events
|
||||
exit 0
|
|
@ -0,0 +1,46 @@
|
|||
#!/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=@ZM_CONFIG@
|
||||
EVENTS_DIR=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
|
||||
|
||||
echo "--- ZM_DB_VERSION=$ZM_VERSION
|
||||
" > $ZM_PATH_WEB/$EVENTS_DIR/$EVENT_PATH/.sql
|
||||
|
||||
$MYSQLDUMP $MYDUMPOPTS --where="Id=$EVENT_ID" zm Events >> $ZM_PATH_WEB/$EVENTS_DIR/$EVENT_PATH/.sql
|
||||
$MYSQLDUMP $MYDUMPOPTS --where="Eventid=$EVENT_ID" zm Frames >> $ZM_PATH_WEB/$EVENTS_DIR/$EVENT_PATH/.sql
|
||||
$MYSQLDUMP $MYDUMPOPTS --where="Eventid=$EVENT_ID" zm Stats >> $ZM_PATH_WEB/$EVENTS_DIR/$EVENT_PATH/.sql
|
||||
|
||||
exit 0
|
|
@ -0,0 +1,20 @@
|
|||
# First the log files
|
||||
|
||||
/var/log/zm/*log {
|
||||
weekly
|
||||
rotate 3
|
||||
notifempty
|
||||
missingok
|
||||
}
|
||||
|
||||
Now the weekly db backup
|
||||
|
||||
/var/lib/zm/zm_backup.sql {
|
||||
weekly
|
||||
rotate 3
|
||||
missingok
|
||||
compress
|
||||
postrotate
|
||||
/usr/lib/zm/bin/zm_db_backup
|
||||
endscript
|
||||
}
|
Loading…
Reference in New Issue