Xtrabackup 全量备份脚本
Posted withfeel
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Xtrabackup 全量备份脚本相关的知识,希望对你有一定的参考价值。
#!/bin/bash
#备份文件的名字为当前主机的IP地址+tar.gz,例如172.16.103.1.tar.gz,且每次备份成功之后都会清空本地的备份目录。
#相关目录
mkdir -p /xtrabackup/mysql
back_dir="/xtrabackup/mysql"
backfilename=`ip add | grep "inet" | grep 172 |grep brd |awk -F / ‘{print $1}‘ | awk -F" " ‘{print $2}‘`
#备份数据库信息
host="127.0.0.1"
dbuser="bakuser"
dbpasswd="Admin123,."
mkdir -p ${back_dir}/log
touch ${back_dir}/log/mysql_xtraback.log
#日志文件
back_log="${back_dir}/log/mysql_xtraback.log"
innobackupex --defaults-file=/etc/my.cnf --host=${host} --user=${dbuser} --password=${dbpasswd} ${back_dir} &>> ${back_log}
if [ $? -eq 0 ]; then
echo "The backup is successful,Next step is Send to server."
tar -zcPf ${backfilename}.tar.gz ${back_dir} && scp ${backfilename}.tar.gz root@172.16.103.6:/root/${backfilename}.tar.gz
if [ $? -eq 0 ]; then
echo "Send successfully completed"
rm -rf ${back_dir}/*
if [ $? -eq 0 ]; then
echo "Cleared local backup directory"
fi
else
echo "Send failed. Check for errors"
fi
else
echo "Backup failed. Check for errors"
?
fi
以上是关于Xtrabackup 全量备份脚本的主要内容,如果未能解决你的问题,请参考以下文章