#!/bin/sh
dumpopts=" -h<host> -u<user> -p<password> --skip-opt --add-drop-table --create-options --disable-keys --extended-insert --quick --set-charset"
_mysqldump="/usr/bin/mysqldump"
_gzip="/bin/gzip -9"
_echo="/bin/echo"
_date="/bin/date"
_find="/usr/bin/find"
cd /server/backup_mysql/sql_dumps
${_echo} "================================="
${_echo} "Backup script by kerya."
${_echo} "================================="
${_echo} " "
for dbname in `mysql -h<host> -u<user> -p<password> -N -B -e "show databases" | grep -v -E "information_schema|<excluded_db1>|<excluded_db2>|<excluded_dbN>"`
do
${_echo} "Backup of db '$dbname' started at $(${_date})"
${_mysqldump} $dumpopts $dbname | ${_gzip} > ${dbname}-`date "+%d.%m.%Y-%H:%M:%S"`.sql.gz;
${_echo} "Backup of db '$dbname' finished at $(${_date})"
${_find} -name "${dbname}*" -mtime 3 -delete
done
exit
-----------------------------------------------------------------------------------------------
/usr/local/bin/mysqlbackup.sh :
#!/bin/bash
nice_=$(which nice)
gzip_=$(which gzip)
tar_=$(which tar)
#mongodump_=$(which mongodump)
list=$(/usr/bin/mysqlshow --defaults-file='/root/.my.cnf' 2>&1 | egrep -v 'Warning: Using a password' | egrep -v '(performance_schema|information_schema|pinba|Databases|-\-)'| tr -d "\|")
for i in $list; do /usr/bin/mysqldump --defaults-file='/root/.my.cnf' --single-transaction --skip-lock-tables --opt -B $i > $i.sql; done
#$mongodump_
#$mongodump_ -db local
#$tar_ czf mongo.tgz dump/ && rm -rf ./dump/
$nice_ -n 20 $gzip_ *.sql
-------------------------------
Чтобы процесс записался в лог, можно использовать команду
tee <filename>
например:
./mysqlbackup.sh | tee mysqlbackup.log
--------------------------------
Полезные ссылки: