One thing I have been asked is a way to backup the configuration in zm and the ability to restore it. Although the code is designed to work with the RPMs I produce, It will also work for anyone else with small changes for the correct paths.
The backup script will place the backup in the users home directory. The retsore script must be run in the same directory as the backup tar.gz.
At least for now, I will inhance the script over time. This is just a quick fix.
So here's the code
This only provides a backup of the configuration. Not event data!
backup-zm
Code: Select all
#!/bin/sh
ZM_CONFIG="/etc/zm.conf"
ZM_BACKUP_PATH="$HOME"
### ZM_PATH line below must be added to /etc/zm.conf or
### uncommented here for this script to work.
# ZM_PATH="/usr/lib/zm"
if [ -f $ZM_CONFIG ]; then
. $ZM_CONFIG
else
echo "ERROR: $ZM_CONFIG not found."
exit 1
fi
echo "Backing up system..."
mysqldump --user=$ZM_DB_USER --password=$ZM_DB_PASS $ZM_DB_NAME Config Controls Filters Groups Monitors States TriggersX10 Users Zones --add-drop-table > /tmp/backup.sql
rm -f $ZM_BACKUP_PATH/zm_backup.tar.gz
tar cvf $ZM_BACKUP_PATH/zm_backup.tar /tmp/backup.sql $ZM_PATH/bin/zmcontrol*.pl $ZM_CONFIG
gzip $ZM_BACKUP_PATH/zm_backup.tar
rm -f /tmp/backup.sql
chmod 666 $ZM_BACKUP_PATH/zm_backup.tar.gz
#chown $ZM_WEB_USER:$ZM_WEB_GROUP $ZM_BACKUP_PATH/zm__backup.tar.gz
echo "Done."
restore-zm
Code: Select all
#!/bin/bash
#
ZM_CONFIG="/etc/zm.conf"
if [ -f $ZM_CONFIG ]; then
. $ZM_CONFIG
else
echo "ERROR: $ZM_CONFIG not found."
exit 1
fi
if [ ! -f zm_backup.tar.gz ] ; then
echo ""
echo "ZM System Restore script"
echo "----------------------------"
echo "run in the same directory as zm_backup.tar.gz"
echo "and this script will restore your configuration."
echo ""
exit 1
fi
echo "## stopping zm"
service zm stop
echo "## Restoring Files"
export BACKUP_LOCATION=`pwd`
cd /
tar xvfz ${BACKUP_LOCATION}/zm_backup.tar.gz
echo "## Restoring Database"
/usr/bin/mysql --user=$ZM_DB_USER --password=$ZM_DB_PASS $ZM_DB_NAME < /tmp/backup.sql
rm -rf /tmp/backup.sql
echo "## Starting zm"
service zm start
echo "## Done."
Corey