ncExportMysql.sh
930 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/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_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