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