千家信息网

mariabackup 增量备份还原

发表于:2025-01-22 作者:千家信息网编辑
千家信息网最后更新 2025年01月22日,1、全备和增量过程命令 mariabackup --backup --target-dir=/var/mariadb/backup/ --user=root --password= m
千家信息网最后更新 2025年01月22日mariabackup 增量备份还原

1、全备和增量过程命令

  mariabackup --backup    --target-dir=/var/mariadb/backup/    --user=root --password=  mariabackup --backup    --target-dir=/var/mariadb/inc1/    --incremental-basedir=/var/mariadb/backup/    --user=root --password=  mariabackup --backup --history   --target-dir=/var/mariadb/inc2/    --incremental-basedir=/var/mariadb/inc1    --user=root --password=  mariabackup --backup --history   --target-dir=/var/mariadb/inc3/    --incremental-basedir=/var/mariadb/inc2    --user=root --password=

2、恢复过程

  mariabackup --prepare --target-dir=/var/mariadb/backup  mariabackup --prepare    --target-dir=/var/mariadb/backup    --incremental-dir=/var/mariadb/inc1  mariabackup --prepare    --target-dir=/var/mariadb/backup    --incremental-dir=/var/mariadb/inc2  mariabackup --prepare    --target-dir=/var/mariadb/backup    --incremental-dir=/var/mariadb/inc3  /etc/init.d/mysql stop  mariabackup --copy-back    --target-dir=/var/mariadb/backup/    /etc/init.d/mysql start

3、特别说明

MariaDB10.2.7以后不再支持使用Percona XtraBackup工具在线物理热备份,所以就自己copy一个类似工具

4、准备备份版本差异

MariaDB starting with 10.2 使用mariabackup --prepare \   --target-dir=/var/mariadb/backupMariaDB until 10.1 使用$ mariabackup --prepare --apply-log-only \   --target-dir=/var/mariadb/backup

5、每周一次全量,其余增量脚本

#!/bin/bashLOCALDIR=/data/mysqlbakWEEKDAY=`date +%u`INTERVARNUM=`expr $WEEKDAY - 1`TISHWEEKFULL=`date -d "$INTERVARNUM day ago" +%F`YESTERDAY=`date -d "1 day ago" +%F`TODAY=`date +%F`FULL=/$LOCALDIR/$TISHWEEKFULL/fullINCR=/$LOCALDIR/$TISHWEEKFULL/incr/$TODAYYESTERDAYDIR=/$LOCALDIR/$TISHWEEKFULL/incr/$YESTERDAYif [ ! -d $FULL ] ;thenecho "没有lsn信息,开始一次全备"     mkdir -p $FULL     /usr/bin/mariabackup --backup --slave-info --kill-long-queries-timeout=120 --kill-long-query-type=select  --target-dir=$FULL/exit 0fimkdir -p $INCRif [ ! -d $YESTERDAYDIR ]  ;then /usr/bin/mariabackup --backup    --slave-info --kill-long-queries-timeout=120 --kill-long-query-type=select         --target-dir=$INCR/  --incremental-basedir=$FULLexit 0fi /usr/bin/mariabackup --backup    --slave-info --kill-long-queries-timeout=120 --kill-long-query-type=select         --target-dir=$INCR/  --incremental-basedir=$YESTERDAYDIR


0