2005-12-28 21:19:29 +01:00
# -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*-
2009-05-22 15:27:09 +02:00
# vim: set filetype=sh sw=3 sts=3 expandtab autoindent:
2005-12-28 20:59:12 +01:00
2005-07-08 21:21:46 +02:00
HELPERS="$HELPERS mysql:mysql_database_backup"
2005-07-04 08:39:00 +02:00
2005-12-27 23:15:40 +01:00
do_mysql_databases() {
REPLY=
while [ -z "$REPLY" ]; do
formBegin "$mysql_title: databases"
formItem "Database:"
2009-05-22 14:50:52 +02:00
formItem "Database:"
formItem "Database:"
formItem "Database:"
formItem "Database:"
formItem "Database:"
formItem "Database:"
formItem "Database:"
formItem "Database:"
formItem "Database:"
2005-12-27 23:15:40 +01:00
formDisplay
[ $? = 0 ] || return 1
mysql_databases="databases = "
for i in $REPLY; do
2009-05-22 14:50:52 +02:00
[ -n "$i" ] && mysql_databases="$mysql_databases $i"
2005-12-27 23:15:40 +01:00
done
done
2005-07-04 08:39:00 +02:00
}
do_mysql_password() {
2009-05-22 14:50:52 +02:00
inputBox "$mysql_title" "specify a mysql user:"
[ $? = 1 ] && return
user=$REPLY
inputBox "$mysql_title" "specify the mysql user's password:"
[ $? = 1 ] && return
password=$REPLY
do_mysql_final "dbusername = $user\ndbpassword = $password"
2005-07-04 08:39:00 +02:00
}
do_mysql_debian() {
2009-05-22 14:50:52 +02:00
_DISABLE_HOTCOPY=yes
do_mysql_final "configfile = /etc/mysql/debian.cnf"
2005-07-04 08:39:00 +02:00
}
do_mysql_user() {
2009-05-22 14:50:52 +02:00
inputBox "$mysql_title" "what system user does mysql backup use?"
[ $? = 1 ] && return
do_mysql_final "user = $REPLY"
2005-07-04 08:39:00 +02:00
}
do_mysql_final() {
if [ -z "$_DISABLE_HOTCOPY" ]; then
2005-12-27 23:15:40 +01:00
checkBox "$mysql_title" "check options" \
2018-11-17 10:51:02 +01:00
"sqldump" "create a backup using mysqldump (more compat)." off \
"hotcopy" "create a backup using mysqlhotcopy (faster)." on \
"compress" "compress the sql output files" on
2005-07-04 08:39:00 +02:00
status=$?
2005-09-03 20:57:37 +02:00
sqldump="sqldump = no"
hotcopy="hotcopy = no"
2005-07-04 08:39:00 +02:00
else
2005-12-27 23:15:40 +01:00
checkBox "$mysql_title" "check options" \
2018-11-17 10:51:02 +01:00
"compress" "compress the sql output files" on
2005-07-04 08:39:00 +02:00
status=$?
2005-09-03 20:57:37 +02:00
sqldump="sqldump = yes"
hotcopy="hotcopy = no"
2005-07-04 08:39:00 +02:00
fi
2009-05-22 14:50:52 +02:00
[ $status = 1 ] && return;
2005-07-04 08:39:00 +02:00
result="$REPLY"
2005-09-03 20:57:37 +02:00
compress="compress = no"
2005-07-04 08:39:00 +02:00
for opt in $result; do
case $opt in
2018-11-17 11:03:30 +01:00
'sqldump') sqldump="sqldump = yes";;
'hotcopy') hotcopy="hotcopy = yes";;
'compress') compress="compress = yes";;
2005-07-04 08:39:00 +02:00
esac
done
get_next_filename $configdirectory/20.mysql
2009-05-22 14:50:52 +02:00
2005-07-04 08:39:00 +02:00
cat >> $next_filename <<EOF
2005-12-27 23:15:40 +01:00
### backupninja MySQL config file ###
# hotcopy = < yes | no > (default = no)
# make a backup of the actual database binary files using mysqlhotcopy.
2005-07-04 08:39:00 +02:00
$hotcopy
2005-12-27 23:15:40 +01:00
# sqldump = < yes | no > (default = no)
# make a backup using mysqldump. this creates text files with sql commands
# sufficient to recontruct the database.
#
$sqldump
2008-12-09 12:40:03 +01:00
# sqldumpoptions = <options>
# (default = --lock-tables --complete-insert --add-drop-table --quick --quote-names)
# arguments to pass to mysqldump
# sqldumpoptions = --add-drop-table --quick --quote-names
2005-12-27 23:15:40 +01:00
# compress = < yes | no > (default = yes)
# if yes, compress the sqldump output.
2005-07-04 08:39:00 +02:00
$compress
2005-12-27 23:15:40 +01:00
# dbhost = <host> (default = localhost)
EOF
cat >> $next_filename <<EOF
# backupdir = <dir> (default: /var/backups/mysql)
# where to dump the backups. hotcopy backups will be in a subdirectory
# 'hotcopy' and sqldump backups will be in a subdirectory 'sqldump'
$mysql_backupdir
# databases = <all | db1 db2 db3 > (default = all)
2009-05-22 14:50:52 +02:00
# which databases to backup. should either be the word 'all' or a
2005-12-27 23:15:40 +01:00
# space separated list of database names.
$mysql_databases
EOF
echo -e $@ >> $next_filename
2009-05-22 14:50:52 +02:00
2005-11-05 00:35:29 +01:00
chmod 600 $next_filename
2005-07-04 08:39:00 +02:00
}
mysql_wizard() {
2009-05-22 14:50:52 +02:00
2005-12-27 23:15:40 +01:00
# Global variables
mysql_title="MySQL action wizard"
2009-05-22 14:50:52 +02:00
2005-12-27 23:15:40 +01:00
# backupdir
2018-06-29 22:50:41 +02:00
inputBox "$mysql_title" "Directory where to store the backups" "/var/backups/mysql"
2005-12-27 23:15:40 +01:00
[ $? = 1 ] && return
mysql_backupdir="backupdir = $REPLY"
# databases
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.\"`"
if [ $? = 0 ]; then
mysql_databases="databases = all"
else
do_mysql_databases
[ $? = 0 ] || return 1
fi
2009-05-22 14:50:52 +02:00
2005-07-04 08:39:00 +02:00
while true; do
_DISABLE_HOTCOPY=
2005-12-27 23:15:40 +01:00
menuBoxHelpFile "$mysql_title" "choose a mysql authentication method:" \
2009-05-22 14:50:52 +02:00
user "change to a linux user first." \
password "manually specify mysql user and password." \
debian "use default mysql user debian-sys-maint."
2005-07-04 08:39:00 +02:00
status=$?
if [ $status = 2 ]; then
2009-05-22 14:50:52 +02:00
# show help.
helptmp="/tmp/backupninja.help.$$"
cat > $helptmp <<EOF
2005-07-04 08:39:00 +02:00
To connect to mysql, backupninja must authenticate.
There are three possible authentication methods:
USER
2009-05-22 14:50:52 +02:00
With this method, you specify a system user. Backupninja will
2005-07-04 08:39:00 +02:00
then become this user before running mysqldump or mysqlhotcopy.
The result is that ~/.my.cnf is used for authentication.
PASSWORD
With this method, you manually specify a mysql user and
password in the backup action configuration.
DEBIAN
With this method, we use the debian-sys-maint user which is
already defined in /etc/mysql/debian.cnf. If you are running
debian, this is recommended, because no further configuration
2009-05-22 14:50:52 +02:00
is needed. The drawback is that this is incompatible with
2005-07-04 08:39:00 +02:00
mysqlhotcopy: you must use mysqldump.
EOF
2009-05-22 14:50:52 +02:00
dialog --textbox $helptmp 0 0
rm $helptmp
2005-07-04 08:39:00 +02:00
fi
[ $status = 1 ] && return;
result="$REPLY"
case "$result" in
"user") do_mysql_user;return;;
"password") do_mysql_password;return;;
"debian") do_mysql_debian;return;;
esac
2009-05-22 14:50:52 +02:00
done
2005-12-28 20:52:22 +01:00
}