sh 备份mysql服务器上的所有数据库,不包括information / performance_schema,包括UDF /存储过程。最有用的安排

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 备份mysql服务器上的所有数据库,不包括information / performance_schema,包括UDF /存储过程。最有用的安排相关的知识,希望对你有一定的参考价值。

#!/bin/bash

# No username or passwords in this script, you should use mysql_config_editor
# to store it securely. The login-path in this script is set to "local-backup" so when you create
# your .mylogin.cnf with the mysql-config-editor make sure it is set the same
# See http://dev.mysql.com/doc/refman/5.6/en/mysql-config-editor.html
# An example to create your config for a mysql user "backup":
# shell> sudo mysql_config_editor set --login-path=local-backup --host=localhost --user=backup --password
# The backup user in the mysql server needs these privileges: SELECT, RELOAD, SHOW DATABASES, REPLICATION CLIENT

DB_BACKUP_DIR_ROOT="/opt/mysql-backups"
DB_BACKUP_DIR_TODAY="$DB_BACKUP_DIR_ROOT/`date +%Y-%m-%d`"
HN=`hostname | awk -F. '{print $1}'`

# Create the backup directory
mkdir -p $DB_BACKUP_DIR_TODAY

# Remove backups older than 1 day
find $DB_BACKUP_DIR_ROOT/ -maxdepth 1 -type d -mtime +1 -exec rm -rf {} \;

# Backup each db in the server, skip schema dbs though
for db in $(mysql --login-path=local-backup -Bse 'show databases'|egrep -vi 'information_schema|performance_schema');
do mysqldump --login-path=local-backup -xQce -R --master-data=2 --max-allowed-packet=1024M -B $db | gzip > "$DB_BACKUP_DIR_TODAY/$HN-$db-$(date +%Y-%m-%dT%H:%M:%S).sql.gz";
done

以上是关于sh 备份mysql服务器上的所有数据库,不包括information / performance_schema,包括UDF /存储过程。最有用的安排的主要内容,如果未能解决你的问题,请参考以下文章

sh 备份MySQL bash所有数据库

sh Bash脚本备份所有MySQL数据库

sh 用于备份所有mysql数据库的脚本

sh 用于备份所有mysql数据库的脚本

sh 用于备份所有mysql数据库的脚本

sh 用于备份所有mysql数据库的脚本