zoukankan      html  css  js  c++  java
  • Mariadb使用xtrabackup工具备份数据脚本

    #!/bin/bash
    #这个脚本用来备份SQL文件;

    sql_home="/home/mysql"
    sql_bak_log="$sql_home/xtrabackup.log"
    server_conf="/usr/local/sunlight/conf/server.conf"
    sql_backup_date=$(date "+%Y%m%d")

    if [ -f $server_conf ];then
    while read line
    do
      eval "$line"
    done < $server_conf
    else
      dbuser="root"
      sql_passwd=""
      dbhost="127.0.0.1"
      sql_port="3306"
    fi

    sql_user="$dbuser"
    sql_passwd="$dbpass"
    sql_host="$dbhost"
    sql_port="$dbport"


    if [ -z "$sql_user" ];then
      echo "Error! sql user is empty!"
      echo "Error! sql user is empty!" >> $sql_bak_log
      exit 1
    fi

    if [ -z "$sql_passwd" ];then
      echo "Error! sql password is empty!"
      echo "Error! sql password is empty!" >> $sql_bak_log
      # exit 1
    fi

    if [ ! -d $sql_home ];then
      mkdir -p $sql_home
      chown mysql:mysql $sql_home
      chmod 700 $sql_home
    fi

    #check mysql daemon
    check_sql_daemon=$(mysql -h"$sql_host" -u"$sql_user"  --password="$sql_passwd" -e "select version();")
    if [ $? -ne 0 ];then
      echo "[ Error ] `date "+%Y/%m/%d %H:%M:%S"` [ msg ] We didn't find mysql daemon!"
      echo "[ Error ] `date "+%Y/%m/%d %H:%M:%S"` [ msg ] We didn't find mysql daemon!" >> $sql_bak_log
      exit 1
    fi

    #check xtrabackup package
    check_xtrabackup_rpm=$(rpm -qa|grep xtrabackup | wc -l)
    if [ $check_xtrabackup_rpm -ne 1 ];then
      echo "[ Error ] `date "+%Y/%m/%d %H:%M:%S"` [ msg ] xtrabackup does not be installed!"
      echo "[ Error ] `date "+%Y/%m/%d %H:%M:%S"` [ msg ] xtrabackup does not be installed!" >> $sql_bak_log
      exit 1
    fi

    if [ -e "$sql_home/${sql_backup_date}.tar.gz" ];then
      rm -f "$sql_home/${sql_backup_date}.tar.gz"
    fi

    sudo -u mysql innobackupex --user=$sql_user --password="$sql_passwd" --socket=/var/lib/mysql/mysql.sock --no-timestamp --stream=tar "$sql_home/" | gzip > "$sql_home/${sql_backup_date}.tar.gz"

    if [ $? -eq 0 ];then
      echo "[ Success ] `date "+%Y/%m/%d %H:%M:%S"` [ msg ] The tar.gz package has been finished !" >> $sql_bak_log
    else
      echo "[ Error ] `date "+%Y/%m/%d %H:%M:%S"` [ msg ] The first backup step has been failed !" >> $sql_bak_log
      echo "-------------------------------------------------------------------------------------------------" >> $sql_bak_log
      exit 1
    fi

    chown mysql:mysql  -R /home/mysql

    chmod 755 -R /home/mysql


    echo "[ Success ] `date "+%Y/%m/%d %H:%M:%S"` Mysql Files Backup Success! " >> $sql_bak_log
    echo "-------------------------------------------------------------------------------------------------" >> $sql_bak_log
    exit 0

  • 相关阅读:
    Java实现 蓝桥杯VIP 算法提高 P0404
    Java实现 蓝桥杯VIP 算法提高 P0404
    Java实现 蓝桥杯VIP 算法提高 P0404
    Java实现 蓝桥杯VIP 算法提高 P0404
    Java实现 蓝桥杯VIP 算法提高 P0404
    Java实现 蓝桥杯VIP 算法训练 排列问题
    Java实现 蓝桥杯VIP 算法训练 排列问题
    Java实现 蓝桥杯VIP 算法训练 排列问题
    Java实现 蓝桥杯VIP 算法训练 排列问题
    关于模态/非模态对话框不响应菜单的UPDATE_COMMAND_UI消息(对对WM_INITMENUPOPUP消息的处理)
  • 原文地址:https://www.cnblogs.com/ralphdc/p/8283076.html
Copyright © 2011-2022 走看看