mysql数据的备份

一、备份方式

1、备份:逻辑备份(mysqldump,mydumper)

2、物理备份(xtrabackup、tar、cp、rsync)   

3、冗余模式:主备模式、数据库集群

二、备份对象

1、数据(库、表)  2、日志文件

三、物理备份(适合大型数据库,不受引擎的限制)实验用的是mariadb,步骤按mysql来

1、percona-xtrabackup 物理备份 + binlog

1.1 下载软件包(两个地址可用,没有fq会比较慢)

Installing Percona XtraBackup on Red Hat Enterprise Linux and CentOS — Percona XtraBackup 8.0 Documentation

https://www.percona.com/downloads/Percona-XtraBackup-LATEST/#

yum install https://repo.percona.com/yum/percona-release-latest.noarch.rpm

yum install percona-xtrabackup-80

yum install qpress

##查看版本
xtrabackup -version
2022-07-06T21:37:27.635178+08:00 0 [Note] [MY-011825] [Xtrabackup] recognized server arguments: --datadir=/var/lib/mysql
xtrabackup version 8.0.28-21 based on MySQL server 8.0.28 Linux (x86_64) (revision id: 78878e9b608)

1.2备份流程

>grant all privileges on  *.* to 'root'@'localhost' identified by '密码';(授权自己定义)

# innobackupex --user=root --password='5740##' /xtrabackup/full  

# cd /xtrabackup/full/ (备份目录)
# ls
2019-11-05_06-38-48

#cat /xtrabackup/full/2017-08-01_00-00-18/xtrabackup_binlog_info  (二进制日志文件)

1.3恢复流程

#systemctl stop mysqld

# innobackupex --apply-log /xtrabackup/full/2017-08-01_00-00-18/ (生成回滚日志)

# innobackupex --copy-back /xtrabackup/full/2017-08-01_00-00-18/  (恢复文件)

1.4增量备份(差异备份及其恢复大致一样)

innobackupex --user=root --password='密码'   --incremental /xtrabackup/   --incremental-basedir=/xtrabackup/2017-09-01_00-00-04

(basedir基于周一的备份。会生成一个今天的。)

2、tar备份数据库(物理备份)

2.1备份

#  systemctl stop  mariadb

#  tar -cf /backup/`date +%F`-mariadb-all.tar  /var/lib/mysql (备份成功)

 2.2恢复

# rm -rf /var/lib/mysql/*
# tar -xf /backup/2016-12-07-mysql-all.tar  -C / (-C / 会让tar包恢复到原来的路径)
# systemctl start mariadb

3、Lvm快照实现物理备份 + binlog(物理备份))

 四、逻辑备份

1、细节不在累述(看官网https://dev.mysql.com/doc/refman/5.7/en/reloading-sql-format-dumps.html

# mysqldump -p'密码' \
--all-databases --single-transaction \    #保证导出的一致性状态--single-transaction
 --master-data=2 \    #master-data=2 注释掉日志记录
--flush-logs \
>  /backup/`date +%F-%H`-mysql-all.sql

2、恢复

 mysql  -p'密码' < /backup/2016-12-08-04-mysql-all.sql

 

 

https://blog.csdn.net/yp090416/article/details/108143521   mysql每天定时自动全库备份、灾备、docker  值得一看

https://www.cnblogs.com/linuxk/p/9371475.html   mysqldump备份和恢复,介绍详细,参数讲解,分引擎备份

Mysql-Xtrabackup全备+增量+还原+实战 (qq.com)

 

https://mp.weixin.qq.com/s/u-TONWrlJFiMenX2fXhFSQ

https://blog.csdn.net/yp090416/article/details/108143521

https://mp.weixin.qq.com/s/Y4jIa0yetzhHGBKwkcAlpA

posted @ 2019-11-05 20:39  凡人半睁眼  阅读(212)  评论(0编辑  收藏  举报