1 # -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*-
2 # vim: set filetype=sh sw=3 sts=3 expandtab autoindent:
4 HELPERS="$HELPERS mysql:mysql_database_backup"
7 choose_one_vserver "$mysql_title"
9 mysql_vsname="vsname = $REPLY"
12 do_mysql_databases() {
14 while [ -z "$REPLY" ]; do
15 formBegin "$mysql_title: databases"
27 [ $? = 0 ] || return 1
28 mysql_databases="databases = "
30 [ -n "$i" ] && mysql_databases="$mysql_databases $i"
36 inputBox "$mysql_title" "specify a mysql user:"
39 inputBox "$mysql_title" "specify the mysql user's password:"
42 do_mysql_final "dbusername = $user\ndbpassword = $password"
47 do_mysql_final "configfile = /etc/mysql/debian.cnf"
51 inputBox "$mysql_title" "what system user does mysql backup use?"
53 do_mysql_final "user = $REPLY"
57 if [ -z "$_DISABLE_HOTCOPY" ]; then
58 checkBox "$mysql_title" "check options" \
59 "sqldump" "create a backup using mysqldump (more compat)." no \
60 "hotcopy" "create a backup using mysqlhotcopy (faster)." yes \
61 "compress" "compress the sql output files" yes
63 sqldump="sqldump = no"
64 hotcopy="hotcopy = no"
66 checkBox "$mysql_title" "check options" \
67 "compress" "compress the sql output files" yes
69 sqldump="sqldump = yes"
70 hotcopy="hotcopy = no"
73 [ $status = 1 ] && return;
75 compress="compress = no"
76 for opt in $result; do
78 '"sqldump"') sqldump="sqldump = yes";;
79 '"hotcopy"') hotcopy="hotcopy = yes";;
80 '"compress"') compress="compress = yes";;
83 get_next_filename $configdirectory/20.mysql
85 cat >> $next_filename <<EOF
86 ### backupninja MySQL config file ###
88 # hotcopy = < yes | no > (default = no)
89 # make a backup of the actual database binary files using mysqlhotcopy.
92 # sqldump = < yes | no > (default = no)
93 # make a backup using mysqldump. this creates text files with sql commands
94 # sufficient to recontruct the database.
98 # sqldumpoptions = <options>
99 # (default = --lock-tables --complete-insert --add-drop-table --quick --quote-names)
100 # arguments to pass to mysqldump
101 # sqldumpoptions = --add-drop-table --quick --quote-names
103 # compress = < yes | no > (default = yes)
104 # if yes, compress the sqldump output.
107 # dbhost = <host> (default = localhost)
110 cat >> $next_filename <<EOF
112 # backupdir = <dir> (default: /var/backups/mysql)
113 # where to dump the backups. hotcopy backups will be in a subdirectory
114 # 'hotcopy' and sqldump backups will be in a subdirectory 'sqldump'
117 # databases = <all | db1 db2 db3 > (default = all)
118 # which databases to backup. should either be the word 'all' or a
119 # space separated list of database names.
124 if [ $host_or_vservers == vservers ]
126 cat >> $next_filename <<EOF
128 # vsname = <vserver> (no default)
129 # vsname indicates which vserver to operate on, this is only used if
130 # vserver is set to yes in /etc/backupninja.conf
131 # NOTE: if you do not specify a vsname the host will be operated on
132 # alsoNOTE: if operating on a vserver, $VROOTDIR will be
133 # prepended to backupdir.
135 echo -e "$mysql_vsname\n" >> $next_filename
138 echo -e $@ >> $next_filename
140 chmod 600 $next_filename
146 mysql_title="MySQL action wizard"
148 # backup the host system or a Vserver?
149 choose_host_or_one_vserver "$mysql_title"
150 [ $? = 0 ] || return 1
151 if [ $host_or_vservers == vservers ]
154 [ $? = 0 ] || return 1
158 if [ $host_or_vservers == vservers ]
160 inputBox "$mysql_title" "Directory where to store the backups:`echo \"\n(Relative to chosen vserver's root directory)\"`" "/var/backups/mysql"
162 inputBox "$mysql_title" "Directory where to store the backups" "/var/backups/mysql"
165 mysql_backupdir="backupdir = $REPLY"
168 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.\"`"
170 mysql_databases="databases = all"
173 [ $? = 0 ] || return 1
178 menuBoxHelpFile "$mysql_title" "choose a mysql authentication method:" \
179 user "change to a linux user first." \
180 password "manually specify mysql user and password." \
181 debian "use default mysql user debian-sys-maint."
183 if [ $status = 2 ]; then
185 helptmp="/tmp/backupninja.help.$$"
187 To connect to mysql, backupninja must authenticate.
188 There are three possible authentication methods:
191 With this method, you specify a system user. Backupninja will
192 then become this user before running mysqldump or mysqlhotcopy.
193 The result is that ~/.my.cnf is used for authentication.
196 With this method, you manually specify a mysql user and
197 password in the backup action configuration.
200 With this method, we use the debian-sys-maint user which is
201 already defined in /etc/mysql/debian.cnf. If you are running
202 debian, this is recommended, because no further configuration
203 is needed. The drawback is that this is incompatible with
204 mysqlhotcopy: you must use mysqldump.
206 dialog --textbox $helptmp 0 0
210 [ $status = 1 ] && return;
213 "user") do_mysql_user;return;;
214 "password") do_mysql_password;return;;
215 "debian") do_mysql_debian;return;;