added cancel
[matthijs/upstream/backupninja.git] / handlers / mysql.helper
1 HELPERS="$HELPERS mysql:mysql_database_backup"
2
3 do_mysql_user() {
4   inputBox "mysql action wizard" "specify a system user:"
5   [ $? = 1 ] && return
6   do_mysql_final "user = $REPLY"
7 }
8
9 do_mysql_password() {
10   inputBox "mysql action wizard" "specify a mysql user:"
11   [ $? = 1 ] && return
12   user=$REPLY
13   inputBox "mysql action wizard" "specify the mysql user's password:"
14   [ $? = 1 ] && return
15   password=$REPLY
16   do_mysql_final "dbusername = $user\ndbpassword = $password"
17 }
18
19 do_mysql_debian() {
20   _DISABLE_HOTCOPY=yes
21   do_mysql_final "configfile = /etc/mysql/debian.cnf"
22 }
23
24 do_mysql_user() {
25   inputBox "mysql action wizard" "what system user does mysql backup use?"
26   [ $? = 1 ] && return
27   do_mysql_final "user = $REPLY"
28 }
29
30 do_mysql_final() {
31    if [ -z "$_DISABLE_HOTCOPY" ]; then
32       checkBox "mysql action wizard" "check options" \
33          "sqldump" "create a backup using mysqldump (more compat)." off \
34          "hotcopy" "create a backup using mysqlhotcopy (faster)." on \
35          "compress" "compress the sql output files" on
36       status=$?
37       sqldump="sqldump = off"
38       hotcopy="hotcopy = off"
39    else
40       checkBox "mysql action wizard" "check options" \
41          "compress" "compress the sql output files" on
42       status=$?
43       sqldump="sqldump = on"
44       hotcopy="hotcopy = off"
45    fi
46
47    [ $status = 1 ] && return;    
48    result="$REPLY"
49    compress="compress = off"
50    for opt in $result; do
51       case $opt in
52         '"sqldump"') sqldump="sqldump = on";;
53         '"hotcopy"') hotcopy="hotcopy = on";;
54         '"compress"') compress="compress = on";;
55       esac
56    done
57    get_next_filename $configdirectory/20.mysql
58    echo -e $@ > $next_filename
59    cat >> $next_filename <<EOF
60 $sqldump
61 $hotcopy
62 $compress
63 # databases   = all
64 # backupdir   = /var/backups/mysql
65 # dbhost      = localhost
66 EOF
67    chmod 000 $next_filename
68 }
69
70 mysql_wizard() {
71    while true; do
72       _DISABLE_HOTCOPY=
73       menuBoxHelpFile "mysql action wizard" "choose a mysql authentication method:" \
74         user "change to a linux user first." \
75         password "manually specify mysql user and password." \
76         debian "use default mysql user debian-sys-maint." 
77       status=$?
78       if [ $status = 2 ]; then
79                # show help.
80           helptmp="/tmp/backupninja.help.$$"
81           cat > $helptmp <<EOF
82 To connect to mysql, backupninja must authenticate.
83 There are three possible authentication methods:
84
85 USER
86 With this method, you specify a system user. Backupninja  will
87 then become this user before running mysqldump or mysqlhotcopy.
88 The result is that ~/.my.cnf is used for authentication.
89
90 PASSWORD
91 With this method, you manually specify a mysql user and
92 password in the backup action configuration.
93
94 DEBIAN
95 With this method, we use the debian-sys-maint user which is
96 already defined in /etc/mysql/debian.cnf. If you are running
97 debian, this is recommended, because no further configuration
98 is needed. The drawback is that this is incompatible with 
99 mysqlhotcopy: you must use mysqldump.
100 EOF
101           dialog --textbox $helptmp 0 0
102           rm $helptmp
103       fi
104
105       [ $status = 1 ] && return;
106       result="$REPLY"
107       case "$result" in
108          "user") do_mysql_user;return;;
109          "password") do_mysql_password;return;;
110          "debian") do_mysql_debian;return;;
111       esac
112    done
113 }
114