#!/bin/sh # # $Id$ # # Script for adding and dropping ser MySql tables # # TO-DO: update_structures command for migriting to new # table definitons # USAGE: call the command without any parameters for info # ################################################################# # config vars ################################################################# DBNAME=ser DBHOST=localhost USERNAME=ser DEFAULT_PW=heslo ROUSER=serro RO_PW=47serro11 CMD="mysql -h $DBHOST -p -u " BACKUP_CMD="mysqldump -h $DBHOST -p -c -t -u " TABLE_TYPE="TYPE=MyISAM" SQL_USER="root" ################################################################# usage() { COMMAND=`basename $0` cat < (restores tables from a file) $COMMAND copy (creates a new db from an existing one) if you want to manipulate database as other MySql user than root, want to change database name from default value "$DBNAME", or want to use other values for users and password, edit the "config vars" section of the command $COMMAND EOF } #usage ser_backup() # pars: { if [ $# -ne 2 ] ; then echo "ser_drop function takes two params" exit 1 fi $BACKUP_CMD $2 $1 } ser_restore() #pars: { if [ $# -ne 3 ] ; then echo "ser_drop function takes two params" exit 1 fi $CMD $2 $1 < $3 } ser_drop() # pars: { if [ $# -ne 2 ] ; then echo "ser_drop function takes two params" exit 1 fi $CMD $2 << EOF drop database $1; EOF } #ser_drop ser_create () # pars: { #test #cat > /tmp/sss < $tmp_file ret=$? if [ "$ret" -ne 0 ]; then rm $tmp_file exit $ret fi ser_create $1 $SQL_USER ret=$? if [ "$ret" -ne 0 ]; then rm $tmp_file exit $ret fi ser_restore $1 $SQL_USER $tmp_file ret=$? rm $tmp_file exit $ret ;; backup) ser_backup $DBNAME $SQL_USER exit $? ;; restore) shift if [ $# -ne 1 ]; then usage exit 1 fi ser_restore $DBNAME $SQL_USER $1 exit $? ;; create) shift if [ $# -eq 1 ] ; then DBNAME="$1" fi ser_create $DBNAME $SQL_USER exit $? ;; drop) ser_drop $DBNAME $SQL_USER exit $? ;; reinit) ser_drop $DBNAME $SQL_USER ret=$? if [ "$ret" -ne 0 ]; then exit $ret fi ser_create $DBNAME $SQL_USER exit $? ;; *) usage exit 1; ;; esac