MySQL——Xtrabackup 备份

目录结构图:

备份命令:./back.sh --backup

恢复命令: ./back.sh -- recover

执行脚本(backup.sh文件脚本):

#!/bin/sh

user=root

password=123456

host=172.16.0.116

dir=$(date +%Y%m%d%H%M)

fullpath=/home/bk/$dir



#备份全库

backup(){

    echo "now start use innobackupex backup database"

    innobackupex  --use-memory=4G --user=$user --password=$password --host=$host --no-timestamp  $fullpath

    echo "backup finish!"

}

##恢复数据库

recover(){

    innobackupex --apply-log --use-memory=4G --user=$user --password=$password --host=$host $fullpath

    innobackupex --copy-back --use-memory=4G --user=$user --password=$password --host=$host $fullpath



}

usage(){

    echo "server_tpl.sh "

    echo "cmd A:功能,注意事项,依赖"

}



casage(){

  ## 函数参数$2 开始有效

  case $1 in

        --help)

          usage

        ;;

        --backup)

          backup $@

        ;;

        --recover)

          recover $@

        ;;

        *)

        echo "没有实现$1功能"

        ;;

    esac

}



if [ $# -lt 1  ] 

then 

    usage

else

    casage $@

fi

问题:

恢复数据后,MySQL启动不了,原因有可能为SELinux未关闭

  1. #查看SELinux状态   状态为 enbaled时为启用

    /usr/sbin/sestatus -v  

  2. #关闭SELinux,临时关闭不需要重启linux

    setenforce 0 

    扫描二维码关注公众号,回复: 5047414 查看本文章

    #setenforce 1 设置SELinux 成为enforcing模式

  3. 修改配置文件需要重启机器:

    修改/etc/selinux/config 文件

    将SELINUX=enforcing改为SELINUX=disabled

    重启机器即可

猜你喜欢

转载自blog.csdn.net/sunfragrence/article/details/84972437