GreatSQL社区

搜索

[已解决] 用脚本对mysql5.7 做xtrabackup的物理备份, 报错

2530 17 2023-5-30 16:51
用脚本对mysql5.7 做xtrabackup的物理备份, 一直报下面的错误。搞了半天搞不定。  关键是另外一个服务器同样的环境就可以执行。哪位大神帮忙看下


报错如下:

[root@localhost bin]# /bin/bash -x backup.sh >> /opt/xtrabackup/backup/log/exec.log
++ dirname backup.sh
+ program_dir=./..
+ conf_file=./../conf/backup.conf
++ sed '/^user=/!d;s/.*=//' ./../conf/backup.conf
+ user=backup
++ sed '/^password=/!d;s/.*=//' ./../conf/backup.conf
+ password=qwerasdf_@
++ sed '/^backup_dir=/!d;s/.*=//' ./../conf/backup.conf
+ backup_dir=/home/backups
++ sed '/^gzip_dir=/!d;s/.*=//' ./../conf/backup.conf
+ gzip_dir=/home/backups/backup_gzip
++ sed '/^xtrabackup_bin=/!d;s/.*=//' ./../conf/backup.conf
+ xtrabackup_bin=/opt/xtrabackup/bin/xtrabackup
++ sed '/^full_backup_prefix=/!d;s/.*=//' ./../conf/backup.conf
+ full_backup_prefix=full
++ sed '/^increment_prefix=/!d;s/.*=//' ./../conf/backup.conf
+ increment_prefix=incr
++ sed '/^error_log=/!d;s/.*=//' ./../conf/backup.conf
+ error_log=./../var/mysql_increment_hot_backup.err
++ sed '/^index_file=/!d;s/.*=//' ./../conf/backup.conf
+ index_file=./../var/mysql_increment_hot_backup.index
++ date +%F
+ backup_date=2023-05-30
++ date +%H-%M-%S
+ backup_time=15-34-49
++ date +%u
+ backup_week_day=2
+ log_dir=./../log/backup
+ var_dir=./../var
+ mkdir -p /home/backups
+ mkdir -p ./../log/backup
+ mkdir -p ./../var
+ mkdir -p /home/backups/backup_gzip
+ main
+ test_conf_file
+ '[' '!' -n backup ']'
+ '[' '!' -n qwerasdf_@ ']'
+ '[' '!' -n /home/backups ']'
+ '[' '!' -n /home/backups/backup_gzip ']'
+ '[' '!' -n full ']'
+ '[' '!' -n incr ']'
+ '[' '!' -n ./../var/mysql_increment_hot_backup.err ']'
+ '[' '!' -n ./../var/mysql_increment_hot_backup.index ']'
+ get_backup_type
+ backup_type=0
++ date +%H
+ '[' 1 -eq 15 ']'
+ backup_type=1
+ touch ./../var/mysql_increment_hot_backup.index
++ cat ./../var/mysql_increment_hot_backup.index
+ '[' '!' -n '{week_day:4,          dir:full_2023-05-25_01-06-01_4,          type:full,          date:2023-05-25}
{week_day:4,          dir:incr_2023-05-25_02-06-01_4,          type:incr,          date:2023-05-25}
{week_day:4,          dir:incr_2023-05-25_03-06-01_4,          type:incr,          date:2023-05-25}
{week_day:4,          dir:incr_2023-05-25_04-06-01_4,          type:incr,          date:2023-05-25}
{week_day:4,          dir:incr_2023-05-25_05-06-01_4,          type:incr,          date:2023-05-25}
{week_day:4,          dir:incr_2023-05-25_06-06-01_4,          type:incr,          date:2023-05-25}
{week_day:4,          dir:incr_2023-05-25_07-06-01_4,          type:incr,          date:2023-05-25}
{week_day:4,          dir:incr_2023-05-25_08-06-02_4,          type:incr,          date:2023-05-25}
{week_day:4,          dir:incr_2023-05-25_09-06-01_4,          type:incr,          date:2023-05-25}
{week_day:4,          dir:incr_2023-05-25_10-06-01_4,          type:incr,          date:2023-05-25}
{week_day:4,          dir:incr_2023-05-25_11-06-01_4,          type:incr,          date:2023-05-25}
{week_day:4,          dir:incr_2023-05-25_12-06-01_4,          type:incr,          date:2023-05-25}
{week_day:4,          dir:incr_2023-05-25_13-06-01_4,          type:incr,          date:2023-05-25}
{week_day:4,          dir:incr_2023-05-25_14-06-01_4,          type:incr,          date:2023-05-25}
{week_day:4,          dir:incr_2023-05-25_15-06-01_4,          type:incr,          date:2023-05-25}' ']'
+ return 1
+ backup_type=1
+ case $backup_type in
+ increment_backup
+ backup_folder=incr_2023-05-30_15-34-49_2
++ sed -n '$p' ./../var/mysql_increment_hot_backup.index
++ awk -F '[, {}]*' '{print $3}'
++ awk -F : '{print $2}'
+ incr_base_folder=incr_2023-05-25_15-06-01_4
+ mkdir -p /home/backups/incr_2023-05-30_15-34-49_2
+ /opt/xtrabackup/bin/xtrabackup --user=backup --password=qwerasdf_@ --backup --target-dir=/home/backups/incr_2023-05-30_15-34-49_2 --incremental-basedir=/home/backups/incr_2023-05-25_15-06-01_4
+ return 1
+ backup_ok=1
+ '[' 1 -eq 0 ']'
+ rm -rf /home/backups/incr_2023-05-30_15-34-49_2
+ logging_backup_err incr
+ echo '{week_day:2,          dir:incr_2023-05-30_15-34-49_2,          type:incr,          date:2023-05-30}'




mysql用来备份的账号

root@mysqldb 15:33:  [(none)]> SHOW GRANTS FOR 'backup'@'localhost';
+----------------------------------------------------------------------------------------------------------+
| Grants for backup@localhost                                                                              |
+----------------------------------------------------------------------------------------------------------+
| GRANT SELECT, RELOAD, PROCESS, LOCK TABLES, REPLICATION CLIENT, SHOW VIEW ON *.* TO 'backup'@'localhost' |
+----------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)



备份脚本

[root@localhost bin]# cat backup.sh
#!/bin/bash
# 获得程序路径名
program_dir=`dirname $0`/..
# 读取配置文件中的所有变量值, 设置为全局变量
# 配置文件
conf_file="$program_dir/conf/backup.conf"
# mysql 用户
user=`sed '/^user=/!d;s/.*=//' $conf_file`
# mysql 密码
password=`sed '/^password=/!d;s/.*=//' $conf_file`
# mysql 备份目录
backup_dir=`sed '/^backup_dir=/!d;s/.*=//' $conf_file`
# mysql 备份压缩打包目录
gzip_dir=`sed '/^gzip_dir=/!d;s/.*=//' $conf_file`
# percona-xtrabackup命令xtrabackup路径
xtrabackup_bin=`sed '/^xtrabackup_bin=/!d;s/.*=//' $conf_file`
# mysql 全备前缀标识
full_backup_prefix=`sed '/^full_backup_prefix=/!d;s/.*=//' $conf_file`
# mysql 增量备前缀标识
increment_prefix=`sed '/^increment_prefix=/!d;s/.*=//' $conf_file`
# 备份错误日志文件
error_log=$program_dir/var/`sed '/^error_log=/!d;s/.*=//' $conf_file`
# 备份索引文件
index_file=$program_dir/var/`sed '/^index_file=/!d;s/.*=//' $conf_file`
# 备份日期
backup_date=`date +%F`
# 备份时间
backup_time=`date +%H-%M-%S`
# 备份时的周几
backup_week_day=`date +%u`

# 创建相关目录
log_dir=$program_dir/log/backup
var_dir=$program_dir/var
mkdir -p $backup_dir
mkdir -p $log_dir
mkdir -p $var_dir
mkdir -p $gzip_dir

# 全量备份

function full_backup() {
  backup_folder=${full_backup_prefix}_${backup_date}_${backup_time}_${backup_week_day}
  mkdir -p $backup_dir/$backup_folder
  $xtrabackup_bin \
    --user=$user \
    --password=$password \
    --backup \
    --target-dir=$backup_dir/$backup_folder > $log_dir/${backup_folder}.log 2>&1
  return $?
}



# 增量备份
function increment_backup() {
  backup_folder=${increment_prefix}_${backup_date}_${backup_time}_${backup_week_day}
  incr_base_folder=`sed -n '$p' $index_file | \
                   awk -F '[, {}]*' '{print $3}' | \
                   awk -F ':' '{print $2}'`
  mkdir -p $backup_dir/$backup_folder
  $xtrabackup_bin \
    --user=$user \
    --password=$password \
    --backup \
    --target-dir=$backup_dir/$backup_folder \
    --incremental-basedir=$backup_dir/$incr_base_folder > $log_dir/${backup_folder}.log 2>&1
  return $?
}

# 删除之前的备份(一般在全备完成后使用)
function delete_before_backup() {
  cat $index_file | awk -F '[, {}]*' '{print $3}' | \
    awk -v backup_dir=$backup_dir -F ':' '{if($2!=""){printf("rm -rf %s/%s\n", backup_dir, $2)}}' | \
    /bin/bash
  cat $index_file | awk -F '[, {}]*' '{print $3}' | \
    awk -v gzip_dir=$gzip_dir -F ':' '{if($2!=""){printf("rm -rf %s/%s\n", gzip_dir, $2)}}' | \
    /bin/bash

  cat $index_file | awk -F '[, {}]*' '{print $3}' | \
    awk -v log_dir=$log_dir -F ':' '{if($2!=""){printf("rm -rf %s/%s.log\n", log_dir, $2)}}' | \
    /bin/bash
}

# 备份索引文件
function backup_index_file() {
  cp $index_file ${index_file}_$(date -d "1 day ago" +%F)
}
# 备份索引文件
function send_index_file_to_remote() {
  ./expect_scp 192.168.3.1118 root k8s90-=uiop ${index_file} /home/backup/index/
  echo 'send index file ok'
}

# 添加索引, 索引记录了当前最新的备份
function append_index_to_file() {
  echo "{week_day: $backup_week_day, \
         dir: ${1}_${backup_date}_${backup_time}_${backup_week_day}, \
         type: ${1}, \
         date: ${backup_date}}" >> $index_file
}

# 记录错误消息到文件
function logging_backup_err() {
  echo "{week_day: $backup_week_day, \
         dir: ${1}_${backup_date}_${backup_time}_${backup_week_day}, \
         type: ${1}, \
         date: ${backup_date}}" >> $error_log
}

# 清空索引
function purge_index_from_file() {
  > $index_file
}

# 清空错误日志信息
function purge_err_log() {
  > $error_log
}

# 打包备份
function tar_backup_file() {
  cd $backup_dir
  tar -jcf ${gzip_dir}/${1}_${backup_date}_${backup_time}_${backup_week_day}.tar.bz2 \
           ${1}_${backup_date}_${backup_time}_${backup_week_day}
  cd - > /dev/null
  #rm -rf ${backup_dir}/${1}_${backup_date}_${backup_time}_${backup_week_day}
}
# 发送备份到远程
function send_backup_to_remote() {
  ./expect_scp 192.168.3.118 root  k8s90-=uiop ${gzip_dir}/${1}_${backup_date}_${backup_time}_${backup_week_day}.tar.bz2 /home/backup/  
  echo "send $1 remote ok"
}

# 判断是应该全备还是增量备份
# 0:full, 1:incr
function get_backup_type() {
  backup_type=0
  if [ 1 -eq `date +%H` ]; then
    backup_type=0
  else
    backup_type=1
  fi
  touch $index_file
  if [ ! -n "`cat $index_file`" ]; then
    backup_type=0
  fi
  return $backup_type
}


# 测试配置文件正确性
function test_conf_file() {
  # 判断每个变量是否在配置文件中有配置,没有则退出程序
  if [ ! -n "$user" ]; then echo 'fail: configure file user not set'; exit 2; fi
  if [ ! -n "$password" ]; then echo 'fail: configure file password not set'; exit 2; fi
  if [ ! -n "$backup_dir" ]; then echo 'fail: configure file backup_dir not set'; exit 2; fi
  if [ ! -n "$gzip_dir" ]; then echo 'fail: configure file backup_dir not set'; exit 2; fi
  if [ ! -n "$full_backup_prefix" ]; then echo 'fail: configure file full_backup_prefix not set'; exit 2; fi
  if [ ! -n "$increment_prefix" ]; then echo 'fail: configure file increment_prefix not set'; exit 2; fi
  if [ ! -n "$error_log" ]; then echo 'fail: configure file error_log not set'; exit 2; fi
  if [ ! -n "$index_file" ]; then echo 'fail: configure file index_file not set'; exit 2; fi
}


# 执行
function main() {
  # 检测配置文件值
  test_conf_file
  # 判断是执行全备还是增量备份
  get_backup_type
  backup_type=$?
  case $backup_type in
    0 )
      # 全量备份
      full_backup
      backup_ok=$?
      if [ 0 -eq "$backup_ok" ]; then
      # 全备成功
        # 打包最新备份
        tar_backup_file $full_backup_prefix
        # # 将tar备份发送到远程
        send_backup_to_remote $full_backup_prefix
        # 备份索引文件
        backup_index_file
        # 清除之前的备份
        delete_before_backup
        # 清除索引文件
        purge_index_from_file
        # 添加索引, 索引记录了当前最新的备份
        append_index_to_file $full_backup_prefix
        # 发送索引文件到远程
        send_index_file_to_remote
      else
      # 全备失败
        # 删除备份目录
        rm -rf ${backup_dir}/${full_backup_prefix}_${backup_date}_${backup_time}_${backup_week_day}
        # 记录错误日志
        logging_backup_err $full_backup_prefix
      fi
      ;;
    1 )
      # 增量备份
      increment_backup
      backup_ok=$?
      if [ "$backup_ok" -eq 0 ]; then
      # 增量备份成功
        # 打包最新备份
        tar_backup_file $increment_prefix
        # # 将tar备份发送到远程
        send_backup_to_remote $increment_prefix
        # 添加索引, 索引记录了当前最新的备份
        append_index_to_file $increment_prefix
        # # 发送索引文件到远程
        send_index_file_to_remote
      else
      # 增量备份失败
        # 删除备份目录
        rm -rf ${backup_dir}/${increment_prefix}_${backup_date}_${backup_time}_${backup_week_day}
        # 记录错误日志
        logging_backup_err $increment_prefix
      fi
      ;;
  esac
}
main



配置参数

[root@localhost bin]# cat /opt/xtrabackup/backup/conf/backup.conf
# mysql 用户名
user=backup
# mysql 密码
password=qwerasdf_@
# 备份路径
backup_dir=/home/backups
# 备份压缩打包目录
gzip_dir=/home/backups/backup_gzip
# innobackupex 命令路径
xtrabackup_bin=/opt/xtrabackup/bin/xtrabackup
# 全量备信息名称 前缀
full_backup_prefix=full
# 增量备信息名称 前缀
increment_prefix=incr
# 错误日志文件(根据此文件知道备份是否成功)
# format:
# {week_day:1,dir:full/incr_2015-12-29_00-00-00_7,type:full/incr,date:2015-12-30}
error_log=mysql_increment_hot_backup.err
# 索引文件
# format:
# {week_day:1,dir:full/incr_2015-12-29_00-00-00_7,type:full/incr,date:2015-12-30}
index_file=mysql_increment_hot_backup.index



全部回复(17)
yejr 2023-5-31 08:06:18
没看到有效错误信息啊,你改成debug模式跑下看看呢
天涯083 2023-5-31 09:34:38
yejr 发表于 2023-5-31 08:06
没看到有效错误信息啊,你改成debug模式跑下看看呢

debug模式如下   
天涯083 2023-5-31 09:35:47

[root@localhost bin]# /bin/bash -x backup1.sh >> /opt/xtrabackup/backup/log/exec.logexit
+ source /opt/xtrabackup/backup/conf/backup1.conf
++ user=myuser
++ password=mypassword
++ backup_dir=/home/backups
++ gzip_dir=/home/backups/backup_gzip
++ xtrabackup_bin=/opt/xtrabackup/bin/xtrabackup
++ full_backup_prefix=full
++ increment_prefix=incr
++ error_log=./../var/mysql_increment_hot_backup.err
++ index_file=./../var/mysql_increment_hot_backup.index
++ remote_user=root
++ remote_host=192.168.3.118
++ remote_backup_dir=/home/backup
+ mkdir -p /home/backups
+ mkdir -p /home/backups/backup_gzip
++ date +%F
+ backup_date=2023-05-30
++ date +%H-%M-%S
+ backup_time=17-50-55
++ date +%u
+ backup_week_day=2
+ main
+ '[' -z myuser ']'
+ '[' -z mypassword ']'
+ '[' -z /home/backups ']'
+ '[' -z /home/backups/backup_gzip ']'
+ '[' -z full ']'
+ '[' -z incr ']'
+ '[' -z ./../var/mysql_increment_hot_backup.err ']'
+ '[' -z ./../var/mysql_increment_hot_backup.index ']'
+ '[' '!' -f ./../var/mysql_increment_hot_backup.index ']'
+ get_backup_type
++ date +%H
+ local current_hour=17
+ '[' 17 -eq 1 ']'
+ backup_type=incremental
+ '[' incremental = full ']'
+ '[' incremental = incremental ']'
+ perform_incremental_backup
++ tail -n 1 ./../var/mysql_increment_hot_backup.index
++ awk -F '[, {}]*' '{print $3}'
+ local last_backup_dir=dir:incr_2023-05-25_15-06-01_4
+ local incremental_backup_dir=/home/backups/incr_2023-05-30_17-50-55_2
+ mkdir -p /home/backups/incr_2023-05-30_17-50-55_2
+ /opt/xtrabackup/bin/xtrabackup --user=myuser --password=mypassword --backup --target-dir=/home/backups/incr_2023-05-30_17-50-55_2 --incremental-basedir=dir:incr_2023-05-25_15-06-01_4
xtrabackup: Error: cannot open /opt/xtrabackup/backup/bin/dir:incr_2023-05-25_15-06-01_4//xtrabackup_checkpoints
xtrabackup: error: failed to read metadata from /opt/xtrabackup/backup/bin/dir:incr_2023-05-25_15-06-01_4//xtrabackup_checkpoints
+ tar -jcf /home/backups/backup_gzip/incr_2023-05-30_17-50-55_2.tar.bz2 /home/backups/incr_2023-05-30_17-50-55_2
tar: Removing leading `/' from member names
+ scp /home/backups/backup_gzip/incr_2023-05-30_17-50-55_2.tar.bz2 root@192.168.3.118:/home/backup
The authenticity of host '192.168.3.118 (192.168.3.118)' can't be established.
ECDSA key fingerprint is SHA256:MlGijDK8NlHluAgWj7VPMLOmfoefPT2EUaibIS3BR7I.
ECDSA key fingerprint is MD5:30:57:66:f7:57:1c:50:01:56:c8:bc:0d:ce:97:e8:45.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.3.118' (ECDSA) to the list of known hosts.
root@192.168.3.118's password:
+ echo '{week_day:2, dir:incr_2023-05-30_17-50-55_2, type:incr, date:2023-05-30}'
ShowMaker 2023-5-31 16:34:44
天涯083 发表于 2023-5-31 09:35
[root@localhost bin]# /bin/bash -x backup1.sh >> /opt/xtrabackup/backup/log/exec.logexit
+ source  ...

你是不是数据库服务器跟192.168.3.118做了互信?debug报错说连接不上192.168.3.118
天涯083 2023-5-31 16:40:44
showmaker 发表于 2023-5-31 16:34
你是不是数据库服务器跟192.168.3.118做了互信?debug报错说连接不上192.168.3.118 ...

是通过账号和密码的方式连接的
天涯083 2023-5-31 16:43:06
天涯083 发表于 2023-5-31 16:40
是通过账号和密码的方式连接的

./expect_scp 192.168.3.118 root  k8s90-=uiop ${gzip_dir}/${1}_${backup_date}_${backup_time}_${backup_week_day}.tar.bz2 /home/backup/     账号和密码也是正确的  [root@localhost backups]# ssh root@192.168.3.118
root@192.168.3.118's password:
Last login: Tue May 30 11:31:58 2023 from 192.168.5.154
ShowMaker 2023-5-31 16:54:04
天涯083 发表于 2023-5-31 16:43
./expect_scp 192.168.3.118 root  k8s90-=uiop ${gzip_dir}/${1}_${backup_date}_${backup_time}_${back ...

+ /opt/xtrabackup/bin/xtrabackup --user=myuser --password=mypassword --backup --target-dir=/home/backups/incr_2023-05-30_17-50-55_2 --incremental-basedir=dir:incr_2023-05-25_15-06-01_4
xtrabackup: Error: cannot open /opt/xtrabackup/backup/bin/dir:incr_2023-05-25_15-06-01_4//xtrabackup_checkpoints
说明: --incremental-basedir 值不对啊,这里应该是绝对路径啊
天涯083 2023-6-1 10:06:04
ShowMaker 发表于 2023-5-31 16:54
+ /opt/xtrabackup/bin/xtrabackup --user=myuser --password=mypassword --backup --target-dir=/home/b ...

换回原来的脚本测试,,现在是这样的报错了 debug模式的:
  [root@localhost bin]# /bin/bash -x backup.sh >> /opt/xtrabackup/backup/log/exec.log
+ set -x
++ dirname backup.sh
+ program_dir=./..
+ conf_file=./../conf/backup.conf
++ sed '/^user=/!d;s/.*=//' ./../conf/backup.conf
+ user=backup
++ sed '/^password=/!d;s/.*=//' ./../conf/backup.conf
+ password=qwerasdf_@
++ sed '/^backup_dir=/!d;s/.*=//' ./../conf/backup.conf
+ backup_dir=/home/backups
++ sed '/^gzip_dir=/!d;s/.*=//' ./../conf/backup.conf
+ gzip_dir=/home/backups/backup_gzip
++ sed '/^xtrabackup_bin=/!d;s/.*=//' ./../conf/backup.conf
+ xtrabackup_bin=/opt/xtrabackup/bin/xtrabackup
++ sed '/^full_backup_prefix=/!d;s/.*=//' ./../conf/backup.conf
+ full_backup_prefix=full
++ sed '/^increment_prefix=/!d;s/.*=//' ./../conf/backup.conf
+ increment_prefix=incr
++ sed '/^error_log=/!d;s/.*=//' ./../conf/backup.conf
+ error_log=./../var/mysql_increment_hot_backup.err
++ sed '/^index_file=/!d;s/.*=//' ./../conf/backup.conf
+ index_file=./../var/mysql_increment_hot_backup.index
++ date +%F
+ backup_date=2023-05-31
++ date +%H-%M-%S
+ backup_time=17-38-39
++ date +%u
+ backup_week_day=3
+ log_dir=./../log/backup
+ var_dir=./../var
+ mkdir -p /home/backups
+ mkdir -p ./../log/backup
+ mkdir -p ./../var
+ mkdir -p /home/backups/backup_gzip
+ main
+ test_conf_file
+ '[' '!' -n backup ']'
+ '[' '!' -n qwerasdf_@ ']'
+ '[' '!' -n /home/backups ']'
+ '[' '!' -n /home/backups/backup_gzip ']'
+ '[' '!' -n full ']'
+ '[' '!' -n incr ']'
+ '[' '!' -n ./../var/mysql_increment_hot_backup.err ']'
+ '[' '!' -n ./../var/mysql_increment_hot_backup.index ']'
+ get_backup_type
+ backup_type=0
++ date +%H
+ '[' 1 -eq 17 ']'
+ backup_type=1
+ touch ./../var/mysql_increment_hot_backup.index
++ cat ./../var/mysql_increment_hot_backup.index
+ '[' '!' -n '{week_day:3,          dir:full_2023-05-31_01-06-01_3,          type:full,          date:2023-05-31}
{week_day:3,          dir:incr_2023-05-31_02-06-01_3,          type:incr,          date:2023-05-31}
{week_day:3,          dir:incr_2023-05-31_03-06-01_3,          type:incr,          date:2023-05-31}
{week_day:3,          dir:incr_2023-05-31_04-06-01_3,          type:incr,          date:2023-05-31}
{week_day:3,          dir:incr_2023-05-31_05-06-02_3,          type:incr,          date:2023-05-31}
{week_day:3,          dir:incr_2023-05-31_06-06-01_3,          type:incr,          date:2023-05-31}
{week_day:3,          dir:incr_2023-05-31_07-06-01_3,          type:incr,          date:2023-05-31}
{week_day:3,          dir:incr_2023-05-31_08-06-01_3,          type:incr,          date:2023-05-31}
{week_day:3,          dir:incr_2023-05-31_09-06-01_3,          type:incr,          date:2023-05-31}
{week_day:3,          dir:incr_2023-05-31_10-06-01_3,          type:incr,          date:2023-05-31}
{week_day:3,          dir:incr_2023-05-31_11-06-01_3,          type:incr,          date:2023-05-31}
{week_day:3,          dir:incr_2023-05-31_12-06-01_3,          type:incr,          date:2023-05-31}
{week_day:3,          dir:incr_2023-05-31_13-06-01_3,          type:incr,          date:2023-05-31}
{week_day:3,          dir:incr_2023-05-31_14-06-01_3,          type:incr,          date:2023-05-31}
{week_day:3,          dir:incr_2023-05-31_15-06-01_3,          type:incr,          date:2023-05-31}' ']'
+ return 1
+ backup_type=1
+ case $backup_type in
+ increment_backup
+ backup_folder=incr_2023-05-31_17-38-39_3
++ sed -n '$p' ./../var/mysql_increment_hot_backup.index
++ awk -F '[, {}]*' '{print $3}'
++ awk -F : '{print $2}'
+ incr_base_folder=incr_2023-05-31_15-06-01_3
+ mkdir -p /home/backups/incr_2023-05-31_17-38-39_3
+ /opt/xtrabackup/bin/xtrabackup --user=backup --password=qwerasdf_@ --backup --target-dir=/home/backups/incr_2023-05-31_17-38-39_3 --incremental-basedir=/home/backups/incr_2023-05-31_15-06-01_3
+ return 1
+ backup_ok=1
+ '[' 1 -eq 0 ']'
+ rm -rf /home/backups/incr_2023-05-31_17-38-39_3
+ logging_backup_err incr
+ echo '{week_day:3,          dir:incr_2023-05-31_17-38-39_3,          type:incr,          date:2023-05-31}'
[root@localhost bin]# source /etc/profile
[root@localhost bin]# /bin/bash -x backup.sh >> /opt/xtrabackup/backup/log/exec.log
+ set -x
++ dirname backup.sh
+ program_dir=./..
+ conf_file=./../conf/backup.conf
++ sed '/^user=/!d;s/.*=//' ./../conf/backup.conf
+ user=backup
++ sed '/^password=/!d;s/.*=//' ./../conf/backup.conf
+ password=qwerasdf_@
++ sed '/^backup_dir=/!d;s/.*=//' ./../conf/backup.conf
+ backup_dir=/home/backups
++ sed '/^gzip_dir=/!d;s/.*=//' ./../conf/backup.conf
+ gzip_dir=/home/backups/backup_gzip
++ sed '/^xtrabackup_bin=/!d;s/.*=//' ./../conf/backup.conf
+ xtrabackup_bin=/opt/xtrabackup/bin/xtrabackup
++ sed '/^full_backup_prefix=/!d;s/.*=//' ./../conf/backup.conf
+ full_backup_prefix=full
++ sed '/^increment_prefix=/!d;s/.*=//' ./../conf/backup.conf
+ increment_prefix=incr
++ sed '/^error_log=/!d;s/.*=//' ./../conf/backup.conf
+ error_log=./../var/mysql_increment_hot_backup.err
++ sed '/^index_file=/!d;s/.*=//' ./../conf/backup.conf
+ index_file=./../var/mysql_increment_hot_backup.index
++ date +%F
+ backup_date=2023-06-01
++ date +%H-%M-%S
+ backup_time=10-02-57
++ date +%u
+ backup_week_day=4
+ log_dir=./../log/backup
+ var_dir=./../var
+ mkdir -p /home/backups
+ mkdir -p ./../log/backup
+ mkdir -p ./../var
+ mkdir -p /home/backups/backup_gzip
+ main
+ test_conf_file
+ '[' '!' -n backup ']'
+ '[' '!' -n qwerasdf_@ ']'
+ '[' '!' -n /home/backups ']'
+ '[' '!' -n /home/backups/backup_gzip ']'
+ '[' '!' -n full ']'
+ '[' '!' -n incr ']'
+ '[' '!' -n ./../var/mysql_increment_hot_backup.err ']'
+ '[' '!' -n ./../var/mysql_increment_hot_backup.index ']'
+ get_backup_type
+ backup_type=0
++ date +%H
+ '[' 1 -eq 10 ']'
+ backup_type=1
+ touch ./../var/mysql_increment_hot_backup.index
++ cat ./../var/mysql_increment_hot_backup.index
+ '[' '!' -n '{week_day:3,          dir:full_2023-05-31_01-06-01_3,          type:full,          date:2023-05-31}
{week_day:3,          dir:incr_2023-05-31_02-06-01_3,          type:incr,          date:2023-05-31}
{week_day:3,          dir:incr_2023-05-31_03-06-01_3,          type:incr,          date:2023-05-31}
{week_day:3,          dir:incr_2023-05-31_04-06-01_3,          type:incr,          date:2023-05-31}
{week_day:3,          dir:incr_2023-05-31_05-06-02_3,          type:incr,          date:2023-05-31}
{week_day:3,          dir:incr_2023-05-31_06-06-01_3,          type:incr,          date:2023-05-31}
{week_day:3,          dir:incr_2023-05-31_07-06-01_3,          type:incr,          date:2023-05-31}
{week_day:3,          dir:incr_2023-05-31_08-06-01_3,          type:incr,          date:2023-05-31}
{week_day:3,          dir:incr_2023-05-31_09-06-01_3,          type:incr,          date:2023-05-31}
{week_day:3,          dir:incr_2023-05-31_10-06-01_3,          type:incr,          date:2023-05-31}
{week_day:3,          dir:incr_2023-05-31_11-06-01_3,          type:incr,          date:2023-05-31}
{week_day:3,          dir:incr_2023-05-31_12-06-01_3,          type:incr,          date:2023-05-31}
{week_day:3,          dir:incr_2023-05-31_13-06-01_3,          type:incr,          date:2023-05-31}
{week_day:3,          dir:incr_2023-05-31_14-06-01_3,          type:incr,          date:2023-05-31}
{week_day:3,          dir:incr_2023-05-31_15-06-01_3,          type:incr,          date:2023-05-31}' ']'
+ return 1
+ backup_type=1
+ case $backup_type in
+ increment_backup
+ backup_folder=incr_2023-06-01_10-02-57_4
++ sed -n '$p' ./../var/mysql_increment_hot_backup.index
++ awk -F '[, {}]*' '{print $3}'
++ awk -F : '{print $2}'
+ incr_base_folder=incr_2023-05-31_15-06-01_3
+ mkdir -p /home/backups/incr_2023-06-01_10-02-57_4
+ /opt/xtrabackup/bin/xtrabackup --user=backup --password=qwerasdf_@ --backup --target-dir=/home/backups/incr_2023-06-01_10-02-57_4 --incremental-basedir=/home/backups/incr_2023-05-31_15-06-01_3
+ return 1
+ backup_ok=1
+ '[' 1 -eq 0 ']'
+ rm -rf /home/backups/incr_2023-06-01_10-02-57_4
+ logging_backup_err incr
+ echo '{week_day:4,          dir:incr_2023-06-01_10-02-57_4,          type:incr,          date:2023-06-01}'
天涯083 2023-6-1 10:06:41
天涯083 发表于 2023-6-1 10:06
换回原来的脚本测试,,现在是这样的报错了 debug模式的:
  [root@localhost bin]# /bin/bash -x backup ...

方便的话,可以向日葵 远程看下吗?谢谢
12下一页
天涯083

1

主题

0

博客

12

贡献

新手上路

Rank: 1

积分
23

助人为乐(铜)

合作电话:010-64087828

社区邮箱:greatsql@greatdb.com

社区公众号
社区小助手
QQ群
GMT+8, 2024-11-23 16:20 , Processed in 0.025261 second(s), 22 queries , Redis On.
快速回复 返回顶部 返回列表