ncExportMysql.sh 916 Bytes
#!/bin/bash
#
#	@package export_import
#	@since 20131205	@author frederick@netz.coop
#
#	exportiert eine Datenbank
#
. basepath.inc.sh
. "$__PATH_to_mcBash/include.inc.sh"

execute=0
logfile="$__PATH_to_Log/$1.log"

mc_h1 "$0 $1 $2 $3 (logfile=$logfile)"
mc_parameter "1" "1" "$1" "mysql Datenbank (muss vorhanden sein)"
mc_parameter "2" "0" "$2" "Datenbankbenutzer (default root)"
mc_parameter "3" "0" "$3" "Datenbankpasswort "



if [ -z $2 ]  ; then
		user='root'
	else
		user=$2
fi

if [ -z $3 ]  ; then
                password=' -p '
        else
                password=" --password=$3 "
fi


DATETIME=$(date +"%Y%m%d_%H%M%S")
BACKUPFILE="mysql.$1.$DATETIME.sql"

mc_bashsu "mysqldump --single-transaction --default-character-set=utf8 -u $user $password $1  > $BACKUPFILE " $execute $logfile
mc_bashsu "tar -czf $BACKUPFILE.tar.gz  $BACKUPFILE" $execute $logfile
mc_bashsu "rm $BACKUPFILE" $execute $logfile