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