1、编写脚本,支持让用户自主选择,使用mysqldump还是xtraback全量备份。
#!/bin/bash
BACKUP_DIR=/data/backup
USER=root
PASSWD=123456
[ -d $BACKUP_DIR ] || mkdir $BACKUP_DIR
while true;do
cat <<EOF
Please input a number to choice you backup:
1.mysqldump
2.xtrabackup
3.quit
EOF
read -p "Your choose: " choose
case "$choose" in
1)
mysqldump -u$USER -p$PASSWD -A -F -E -R --single-transaction --master-data=1 --flush-privileges --triggers --default-character-set=utf8 --hex-blob > $BACKUP_DIR/fullbak_$(date +%F_%T).sql
;;
2)
innobackupex --user=$USER --password=$PASSWD $BACKUP_DIR
;;
3)
echo "Bye!" && exit 2
;;
*)
echo "Choose Error !" && exit 3
;;
esac
done
2、配置Mysql主从同步
(1)、两台主机都安装好mariadb-server数据库
yum install -y mariadb-server
(2)、配置主服务器
vim /etc/my.cnf
server_id=1
log-bin=/data/logbin/mysql
systemctl restart mariadb
mysql
grant replication slave on *.* to repluser@‘192.168.5.%‘ identified by ‘123456‘ ;
show master logs
(3)、配置从服务器
vim /etc/my.cnf
server_id=2
read-only
show slave status\G ;
CHANGE MASTER TO
MASTER_HOST=‘192.168.5.12‘,
MASTER_USER=‘repluser‘,
MASTER_PASSWORD=‘123456‘,
MASTER_PORT=3306,
MASTER_LOG_FILE=‘mysql.000002‘,
MASTER_LOG_POS=245;
show slave status\G
start slave ;
show slave status\G
show processlist ;