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

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

mc_e "$0 !database!	dbuser		dbpasswd	filepreafix"
mc_e "$0 $1		$2		$3		$4	(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 "
mc_parameter "4" "0" "$4" "Datei Praefix "



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

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

if [ -z $4 ]  ; then
		praefix='db'
	else
		praefix="$4.db"
fi

DATETIME=$(date +"%Y%m%d_%H%M%S")
BACKUPFILE="$praefix.$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