#! /usr/bin/env bash
#############################################################################
# This program is part of Zenoss Core, an open source monitoring platform.
# Copyright (C) 2007, Zenoss Inc.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 as published by
# the Free Software Foundation.
#
# For complete information please visit: http://www.zenoss.com/oss/
#############################################################################

# Dump events in the MySQL in memory table status
# Make sure that MYUSER MYPASS and MYSQLHOME are set properly
# The backup file can be loaded back into the database using:
#    use events;
#    load data infile '/usr/local/mysql/backup/status.data' into table status;
# put these commands in a file and use it in the init-file parameter to mysqld

MYUSER=root
MYPASS=PASS

MYSQLHOME=/usr/local/mysql

MYSQL=$MYSQLHOME/bin/mysql
BKDIR=$MYSQLHOME/backup
BKFILE=$BKDIR/status.data

if [ ! -e $BKDIR ]; then
    mkdir -p $BKDIR
    chown mysql $BKDIR
fi

rm -f $BKFILE

echo "select * from status into outfile \"$BKFILE\";" | $MYSQL -u $MYUSER --password=$MYPASS events

