mirror of
https://0xacab.org/liberate/backupninja.git
synced 2024-11-23 11:13:18 +01:00
mysql --defaults-file stuff.
This commit is contained in:
parent
e2089c77cb
commit
1b3449f24c
@ -3,7 +3,7 @@
|
|||||||
# B A C K U P N I N J A /()/
|
# B A C K U P N I N J A /()/
|
||||||
# `\|
|
# `\|
|
||||||
#
|
#
|
||||||
# Copyright (C) 2004 riseup.net -- property is theft.
|
# Copyright (C) 2004-05 riseup.net -- property is theft.
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
@ -429,7 +429,7 @@ getconf RSYNC /usr/bin/rsync
|
|||||||
getconf vservers no
|
getconf vservers no
|
||||||
getconf VSERVERINFO /usr/sbin/vserver-info
|
getconf VSERVERINFO /usr/sbin/vserver-info
|
||||||
getconf VSERVER /usr/sbin/vserver
|
getconf VSERVER /usr/sbin/vserver
|
||||||
getconf VROOTDIR `$VSERVERINFO info SYSINFO |grep vserver-Rootdir | awk '{print $2}'`
|
getconf VROOTDIR `if [ -f "$VSERVERINFO" ]; then $VSERVERINFO info SYSINFO |grep vserver-Rootdir | awk '{print $2}'; fi`
|
||||||
|
|
||||||
if [ ! -d "$configdirectory" ]; then
|
if [ ! -d "$configdirectory" ]; then
|
||||||
echo "Configuration directory '$configdirectory' not found."
|
echo "Configuration directory '$configdirectory' not found."
|
||||||
@ -443,8 +443,8 @@ if [ "$UID" != "0" ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$VSERVERS" = "yes" -a ! -d $VROOTDIR ]; then
|
if [ "$vservers" == "yes" -a ! -d "$VROOTDIR" ]; then
|
||||||
echo "vservers option set in config, but $VROOTDIR is not a directory!"
|
echo "vservers option set in config, but $VROOTDIR is not a directory!"
|
||||||
fatal "vservers option set in config, but $VROOTDIR is not a directory!"
|
fatal "vservers option set in config, but $VROOTDIR is not a directory!"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -17,9 +17,9 @@ version 0.x -- xxxxxxxxxxxxx
|
|||||||
added "bandwidthlimit" option
|
added "bandwidthlimit" option
|
||||||
example.dup example config file for duplicity handler
|
example.dup example config file for duplicity handler
|
||||||
added trac (http://trac.edgewall.com/) environment handler (thanks Charles Lepple!)
|
added trac (http://trac.edgewall.com/) environment handler (thanks Charles Lepple!)
|
||||||
added configfile option to mysql handler (thanks bonniot!)
|
added configfile option to mysql handler
|
||||||
uses /etc/mysql/debian.cnf by default
|
the default is /etc/mysql/debian.cnf. with this,
|
||||||
now, an empty /etc/backup.d/01.mysql file is all you need
|
sqldump doesn't need dbusername. (hotcopy still does).
|
||||||
|
|
||||||
version 0.5 -- April 12 2005
|
version 0.5 -- April 12 2005
|
||||||
rdiff handler works when remote sshd has a banner
|
rdiff handler works when remote sshd has a banner
|
||||||
|
@ -1,24 +1,31 @@
|
|||||||
## backupninja mysql config file ##
|
### backupninja mysql config file ###
|
||||||
|
|
||||||
dbhost = localhost
|
|
||||||
databases = all
|
databases = all
|
||||||
backupdir = /var/backups/mysql
|
backupdir = /var/backups/mysql
|
||||||
hotcopy = yes
|
hotcopy = no
|
||||||
sqldump = no
|
sqldump = yes
|
||||||
compress = yes
|
compress = yes
|
||||||
|
|
||||||
## authentication ##
|
### authentication ###
|
||||||
|
|
||||||
configfile = /etc/mysql/debian.cnf
|
# three authentication methods:
|
||||||
|
#
|
||||||
|
# 1. setting the user, so that /home/user/.my.cnf is used.
|
||||||
|
# user = some-unix-user
|
||||||
|
#
|
||||||
|
# 2. specifying the mysql dbuser and dbpassword,
|
||||||
|
# which generates a temporary .my.cnf in /root/.my.cnf
|
||||||
|
# dbusername = <some-mysql-user>
|
||||||
|
# dbpassword = <password>
|
||||||
|
#
|
||||||
|
# 3. specify which config file to use with configfile
|
||||||
|
# (this option does not work with hotcopy)
|
||||||
|
# configfile = /etc/mysql/debian.cnf
|
||||||
|
#
|
||||||
|
# if user and dbusername are not specified, the default is to use
|
||||||
|
# /etc/mysql/debian.cnf for configfile.
|
||||||
|
|
||||||
# or...
|
### all options ###
|
||||||
# dbusername = <dbuser>
|
|
||||||
# dbpassword = <dbpassword>
|
|
||||||
|
|
||||||
# or...
|
|
||||||
# user = root
|
|
||||||
|
|
||||||
## notes ##
|
|
||||||
|
|
||||||
# configfile = < path/to/file > (default = /etc/mysql/debian.cnf)
|
# configfile = < path/to/file > (default = /etc/mysql/debian.cnf)
|
||||||
# The config file is passed to mysql with --defaults-file.
|
# The config file is passed to mysql with --defaults-file.
|
||||||
@ -50,7 +57,7 @@ configfile = /etc/mysql/debian.cnf
|
|||||||
# where to dump the backups. hotcopy backups will be in a subdirectory 'hotcopy' and
|
# where to dump the backups. hotcopy backups will be in a subdirectory 'hotcopy' and
|
||||||
# sqldump backups will be in a subdirectory 'sqldump'
|
# sqldump backups will be in a subdirectory 'sqldump'
|
||||||
#
|
#
|
||||||
# hotcopy = < yes | no > (default = yes)
|
# hotcopy = < yes | no > (default = no)
|
||||||
# make a backup of the actual database binary files using mysqlhotcopy.
|
# make a backup of the actual database binary files using mysqlhotcopy.
|
||||||
#
|
#
|
||||||
# sqldump = < yes | no > (default = no)
|
# sqldump = < yes | no > (default = no)
|
||||||
|
@ -3,16 +3,27 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
getconf backupdir /var/backups/mysql
|
getconf backupdir /var/backups/mysql
|
||||||
getconf configfile /etc/mysql/debian.cnf
|
|
||||||
getconf databases all
|
getconf databases all
|
||||||
|
getconf dbhost localhost
|
||||||
|
getconf hotcopy no
|
||||||
|
getconf sqldump no
|
||||||
getconf compress yes
|
getconf compress yes
|
||||||
|
getconf vsname
|
||||||
|
|
||||||
|
# authentication:
|
||||||
|
getconf user
|
||||||
getconf dbusername
|
getconf dbusername
|
||||||
getconf dbpassword
|
getconf dbpassword
|
||||||
getconf dbhost localhost
|
getconf configfile /etc/mysql/debian.cnf
|
||||||
getconf hotcopy yes
|
|
||||||
getconf sqldump no
|
if [ "$user" == "" ]; then
|
||||||
getconf user root
|
userset=false;
|
||||||
getconf vsname
|
user=root;
|
||||||
|
else
|
||||||
|
userset=true;
|
||||||
|
userhome=`grep "^$user:" /etc/passwd | awk -F: '{print $6}'`
|
||||||
|
[ -f $userhome/.my.cnf ] || fatal "Can't find config file in $userhome/.my.cnf"
|
||||||
|
fi
|
||||||
|
|
||||||
# If vservers are configured, decide if the handler should
|
# If vservers are configured, decide if the handler should
|
||||||
# use them or if it should just operate on the host
|
# use them or if it should just operate on the host
|
||||||
@ -51,17 +62,33 @@ else
|
|||||||
[ "$hotcopy" == "no" -o -d $hotdir ] || mkdir -p $hotdir
|
[ "$hotcopy" == "no" -o -d $hotdir ] || mkdir -p $hotdir
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
#######################################################################
|
||||||
|
## AUTHENTICATION
|
||||||
|
|
||||||
|
#
|
||||||
|
# one of three authentication methods:
|
||||||
|
# 1. setting the user, so that /home/user/.my.cnf is used.
|
||||||
|
# 2. specifying the user and password in the handler config,
|
||||||
|
# which generates a temporary .my.cnf in /root/.my.cnf
|
||||||
|
# 3. specify the config file with --defaults-file
|
||||||
|
# (this option DOESN'T WORK WITH MYSQLHOTCOPY)
|
||||||
|
#
|
||||||
|
|
||||||
# create .my.cnf
|
# create .my.cnf
|
||||||
# only if dbusername and dbpassword specified.
|
# only if dbusername and dbpassword specified.
|
||||||
# we create a tmp file because we don't want to have to
|
# we create a tmp file because we don't want to
|
||||||
# specify the password on the command line.
|
# specify the password on the command line.
|
||||||
|
|
||||||
defaultsfile=""
|
defaultsfile=""
|
||||||
if [ "$dbusername" != "" -a "$dbpassword" != "" ]; then
|
if [ "$dbusername" != "" -a "$dbpassword" != "" ]; then
|
||||||
mycnf="/tmp/backupninja.$$.my.cnf"
|
home=`grep '^root:' /etc/passwd | awk -F: '{print $6}'`
|
||||||
|
[ -d $home ] || fatal "Can't find root's home directory ($home)."
|
||||||
|
mycnf="$home/.my.cnf"
|
||||||
if [ -f $mycnf ]; then
|
if [ -f $mycnf ]; then
|
||||||
debug "rm $mycnf"
|
# rename temporarily
|
||||||
rm $mycnf
|
tmpcnf="$home/my.cnf.disable"
|
||||||
|
debug "mv $mycnf $tmpcnf"
|
||||||
|
mv $mycnf $tmpcnf
|
||||||
fi
|
fi
|
||||||
oldmask=`umask`
|
oldmask=`umask`
|
||||||
umask 077
|
umask 077
|
||||||
@ -80,21 +107,22 @@ user=$dbusername
|
|||||||
password=$dbpassword
|
password=$dbpassword
|
||||||
EOF
|
EOF
|
||||||
umask $oldmask
|
umask $oldmask
|
||||||
defaultsfile="--defaults-file $mycnf"
|
defaultsfile="--defaults-file=$mycnf"
|
||||||
else
|
elif [ "$userset" == "false" ]; then
|
||||||
# otherwise, use $configfile
|
# if user is set, don't use $configfile
|
||||||
defaultsfile="--defaults-file $configfile"
|
defaultsfile="--defaults-file=$configfile"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
#######################################################################
|
||||||
## HOT COPY
|
## HOT COPY
|
||||||
|
|
||||||
if [ "$hotcopy" == "yes" ]; then
|
if [ "$hotcopy" == "yes" ]; then
|
||||||
if [ "$databases" == "all" ]; then
|
if [ "$databases" == "all" ]; then
|
||||||
if [ $usevserver ]
|
if [ $usevserver ]
|
||||||
then
|
then
|
||||||
execstr="$VSERVER $vsname exec $MYSQLHOTCOPY $defaultsfile --quiet --allowold --regexp /.\*/./.\*/ $hotdir"
|
execstr="$VSERVER $vsname exec $MYSQLHOTCOPY --quiet --allowold --regexp /.\*/./.\*/ $hotdir"
|
||||||
else
|
else
|
||||||
execstr="$MYSQLHOTCOPY $defaultsfile --quiet --allowold --regexp /.\*/./.\*/ $hotdir"
|
execstr="$MYSQLHOTCOPY --quiet --allowold --regexp /.\*/./.\*/ $hotdir"
|
||||||
fi
|
fi
|
||||||
debug "su $user -c '$execstr'"
|
debug "su $user -c '$execstr'"
|
||||||
if [ ! $test ]; then
|
if [ ! $test ]; then
|
||||||
@ -112,9 +140,9 @@ if [ "$hotcopy" == "yes" ]; then
|
|||||||
for db in $databases; do
|
for db in $databases; do
|
||||||
if [ $usevserver ]
|
if [ $usevserver ]
|
||||||
then
|
then
|
||||||
execstr="$VSERVER $vsname exec $MYSQLHOTCOPY $defaultsfile --allowold $db $hotdir"
|
execstr="$VSERVER $vsname exec $MYSQLHOTCOPY --allowold $db $hotdir"
|
||||||
else
|
else
|
||||||
execstr="$MYSQLHOTCOPY $defaultsfile --allowold $db $hotdir"
|
execstr="$MYSQLHOTCOPY --allowold $db $hotdir"
|
||||||
fi
|
fi
|
||||||
debug "su $user -c '$execstr'"
|
debug "su $user -c '$execstr'"
|
||||||
if [ ! $test ]; then
|
if [ ! $test ]; then
|
||||||
@ -131,7 +159,8 @@ if [ "$hotcopy" == "yes" ]; then
|
|||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
##########################################################################
|
||||||
## SQL DUMP
|
## SQL DUMP
|
||||||
|
|
||||||
if [ "$sqldump" == "yes" ]; then
|
if [ "$sqldump" == "yes" ]; then
|
||||||
@ -172,9 +201,14 @@ if [ "$sqldump" == "yes" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# clean up tmp config file
|
# clean up tmp config file
|
||||||
if [ -f "$mycnf" ]; then
|
if [ "$dbusername" != "" ]; then
|
||||||
|
## clean up tmp config file
|
||||||
debug "rm $mycnf"
|
debug "rm $mycnf"
|
||||||
rm $mycnf
|
rm $mycnf
|
||||||
|
if [ -f "$tmpcnf" ]; then
|
||||||
|
debug "mv $tmpcnf $mycnf"
|
||||||
|
mv $tmpcnf $mycnf
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
Loading…
Reference in New Issue
Block a user