fixed autotools build, broken since r466, inhandlers/Makefile.am
[matthijs/upstream/backupninja.git] / handlers / mysql.helper.in
1 # -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*-
2
3 HELPERS="$HELPERS mysql:mysql_database_backup"
4
5 do_mysql_vserver() {
6    choose_one_vserver "$mysql_title"
7    [ $? = 0 ] || return 1
8    mysql_vsname="vsname = $REPLY"
9 }
10
11 do_mysql_databases() {
12    REPLY=
13    while [ -z "$REPLY" ]; do
14       formBegin "$mysql_title: databases"
15          formItem "Database:"
16          formItem "Database:"
17          formItem "Database:"
18          formItem "Database:"
19          formItem "Database:"
20          formItem "Database:"
21          formItem "Database:"
22          formItem "Database:"
23          formItem "Database:"
24          formItem "Database:"
25       formDisplay
26       [ $? = 0 ] || return 1
27       mysql_databases="databases = "
28       for i in $REPLY; do
29          [ -n "$i" ] && mysql_databases="$mysql_databases $i"
30       done
31    done
32 }
33
34 do_mysql_password() {
35   inputBox "$mysql_title" "specify a mysql user:"
36   [ $? = 1 ] && return
37   user=$REPLY
38   inputBox "$mysql_title" "specify the mysql user's password:"
39   [ $? = 1 ] && return
40   password=$REPLY
41   do_mysql_final "dbusername = $user\ndbpassword = $password"
42 }
43
44 do_mysql_debian() {
45   _DISABLE_HOTCOPY=yes
46   do_mysql_final "configfile = /etc/mysql/debian.cnf"
47 }
48
49 do_mysql_user() {
50   inputBox "$mysql_title" "what system user does mysql backup use?"
51   [ $? = 1 ] && return
52   do_mysql_final "user = $REPLY"
53 }
54
55 do_mysql_final() {
56    if [ -z "$_DISABLE_HOTCOPY" ]; then
57       checkBox "$mysql_title" "check options" \
58          "sqldump" "create a backup using mysqldump (more compat)." no \
59          "hotcopy" "create a backup using mysqlhotcopy (faster)." yes \
60          "compress" "compress the sql output files" yes
61       status=$?
62       sqldump="sqldump = no"
63       hotcopy="hotcopy = no"
64    else
65       checkBox "$mysql_title" "check options" \
66          "compress" "compress the sql output files" yes
67       status=$?
68       sqldump="sqldump = yes"
69       hotcopy="hotcopy = no"
70    fi
71
72    [ $status = 1 ] && return;    
73    result="$REPLY"
74    compress="compress = no"
75    for opt in $result; do
76       case $opt in
77         '"sqldump"') sqldump="sqldump = yes";;
78         '"hotcopy"') hotcopy="hotcopy = yes";;
79         '"compress"') compress="compress = yes";;
80       esac
81    done
82    get_next_filename $configdirectory/20.mysql
83    
84    cat >> $next_filename <<EOF
85 ### backupninja MySQL config file ###
86
87 # hotcopy = < yes | no > (default = no)
88 # make a backup of the actual database binary files using mysqlhotcopy.
89 $hotcopy
90
91 # sqldump = < yes | no > (default = no)
92 # make a backup using mysqldump. this creates text files with sql commands
93 # sufficient to recontruct the database.
94 #
95 $sqldump
96
97 # compress = < yes | no > (default = yes)
98 # if yes, compress the sqldump output.
99 $compress
100
101 # dbhost      = <host> (default = localhost)
102
103 EOF
104    cat >> $next_filename <<EOF
105
106 # backupdir = <dir> (default: /var/backups/mysql)
107 # where to dump the backups. hotcopy backups will be in a subdirectory
108 # 'hotcopy' and sqldump backups will be in a subdirectory 'sqldump'
109 $mysql_backupdir
110
111 # databases = <all | db1 db2 db3 > (default = all)
112 # which databases to backup. should either be the word 'all' or a 
113 # space separated list of database names.
114 $mysql_databases
115
116 EOF
117
118 if [ $host_or_vservers == vservers ]
119    then
120        cat >> $next_filename <<EOF
121 #
122 # vsname = <vserver> (no default)
123 # vsname indicates which vserver to operate on, this is only used if 
124 # vserver is set to yes in /etc/backupninja.conf
125 # NOTE: if you do not specify a vsname the host will be operated on
126 # alsoNOTE: if operating on a vserver, $VROOTDIR will be 
127 # prepended to backupdir.
128 EOF
129    echo -e "$mysql_vsname\n" >> $next_filename
130 fi
131
132    echo -e $@ >> $next_filename
133    
134    chmod 600 $next_filename
135 }
136
137 mysql_wizard() {
138    
139    # Global variables
140    mysql_title="MySQL action wizard"
141    
142    # backup the host system or a Vserver?
143    choose_host_or_one_vserver "$mysql_title"
144    [ $? = 0 ] || return 1
145    if [ $host_or_vservers == vservers ]
146    then
147        do_mysql_vserver
148        [ $? = 0 ] || return 1
149    fi
150       
151    # backupdir
152    if [ $host_or_vservers == vservers ]
153    then
154        inputBox "$mysql_title" "Directory where to store the backups:`echo \"\n(Relative to chosen vserver's root directory)\"`" "/var/backups/mysql"
155    else
156        inputBox "$mysql_title" "Directory where to store the backups" "/var/backups/mysql"
157    fi
158    [ $? = 1 ] && return
159    mysql_backupdir="backupdir = $REPLY"
160
161    # databases
162    booleanBox "$mysql_title" "Do you want to backup all of the databases? `echo \"\n\nIf not, you'll be offered to choose individual databases to backup.\"`"
163    if [ $? = 0 ]; then
164       mysql_databases="databases = all"
165    else
166       do_mysql_databases
167       [ $? = 0 ] || return 1
168    fi
169    
170    while true; do
171       _DISABLE_HOTCOPY=
172       menuBoxHelpFile "$mysql_title" "choose a mysql authentication method:" \
173         user "change to a linux user first." \
174         password "manually specify mysql user and password." \
175         debian "use default mysql user debian-sys-maint." 
176       status=$?
177       if [ $status = 2 ]; then
178                # show help.
179           helptmp="/tmp/backupninja.help.$$"
180           cat > $helptmp <<EOF
181 To connect to mysql, backupninja must authenticate.
182 There are three possible authentication methods:
183
184 USER
185 With this method, you specify a system user. Backupninja  will
186 then become this user before running mysqldump or mysqlhotcopy.
187 The result is that ~/.my.cnf is used for authentication.
188
189 PASSWORD
190 With this method, you manually specify a mysql user and
191 password in the backup action configuration.
192
193 DEBIAN
194 With this method, we use the debian-sys-maint user which is
195 already defined in /etc/mysql/debian.cnf. If you are running
196 debian, this is recommended, because no further configuration
197 is needed. The drawback is that this is incompatible with 
198 mysqlhotcopy: you must use mysqldump.
199 EOF
200           dialog --textbox $helptmp 0 0
201           rm $helptmp
202       fi
203
204       [ $status = 1 ] && return;
205       result="$REPLY"
206       case "$result" in
207          "user") do_mysql_user;return;;
208          "password") do_mysql_password;return;;
209          "debian") do_mysql_debian;return;;
210       esac
211    done   
212 }