xtrabackup 2.4使用方法

全量备份
创建备份用户

create user 'raybak'@'%' identified by 'raybak';
grant reload,lock tables,replication client,process,super on *.* to 'raybak'@'%';
flush privileges;

创建备份目录

mkdir -p /mysql/backup

全备数据库

./innobackupex --defaults-file=/mysql/my3306/my.cnf --no-timestamp --user raybak --password raybak /mysql/backup/full20221208

删除数据库ray

mysql> drop database ray;
Query OK, 1 row affected (0.02 sec)
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| lei                |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.00 sec)

恢复数据库

./innobackupex --defaults-file=/mysql/my3306/my.cnf --user=raybak --password raybak --apply-log /mysql/backup/full20221208

关闭数据库

mysqladmin -uroot -prootroot shutdown

重命名原来的数据目录

[root@ray1 ~]# cd /mysqldata/my3306/
[root@ray1 my3306]# mv data/ data_old

新备份集mv到数据目录

[root@ray1 ~]# cd /mysql/backup/
[root@ray1 backup]# mv full20221208/ /mysqldata/my3306/data

更改数据库文件目录所属用户和属组

[root@ray1 ~]# cd /mysqldata/my3306/
[root@ray1 my3306]# chown -R mysql:mysql data

启动MySQL数据库

[root@ray1 my3306]# systemctl start mysqld
[root@ray1 my3306]# mysql -uroot -prootroot
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.38-log MySQL Community Server (GPL)
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| lei                |
| mysql              |
| performance_schema |
| ray                |
| sys                |
+--------------------+
6 rows in set (0.00 sec)

增量备份数据库
查看上一次全备的起始LSN

[root@ray1 full20221208]# cat xtrabackup_checkpoints
backup_type = full-backuped
from_lsn = 0
to_lsn = 215551181
last_lsn = 215551190
compact = 0
recover_binlog_info = 0
flushed_lsn = 215551190

执行增量备份

./innobackupex --defaults-file=/mysql/my3306/my.cnf --no-timestamp --user raybak --password raybak --incremental /mysql/backup/incre20221209 --incremental-basedir=/mysql/backup/full20221208

增量恢复数据库
全量恢复数据库

./innobackupex --defaults-file=/mysql/my3306/my.cnf --user raybak --password raybak --apply-log --redo-only /mysql/backup/full20221208

恢复增量

./innobackupex --defaults-file=/mysql/my3306/my.cnf --user raybak --password raybak --apply-log --redo-only /mysql/backup/full20221208 --incremental-dir=/mysql/backup/incre20221209

恢复全量

./innobackupex --defaults-file=/mysql/my3306/my.cnf --user raybak --password raybak --apply-log /mysql/backup/full20221208

关闭数据库

mysqladmin -uroot -prootroot shutdown

重命名原来的数据目录

[root@ray1 ~]# cd /mysqldata/my3306/
[root@ray1 my3306]# mv data/ data_old

新备份集mv到数据目录

[root@ray1 ~]# cd /mysql/backup/
[root@ray1 backup]# cp -r full20221208/ /mysqldata/my3306/data

更改数据库文件目录所属用户和属组

[root@ray1 ~]# cd /mysqldata/my3306/
[root@ray1 my3306]# chown -R mysql:mysql data

启动MySQL数据库

[root@ray1 my3306]# systemctl start mysqld
[root@ray1 my3306]# mysql -uroot -prootroot
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.38-log MySQL Community Server (GPL)
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| lei                |
| mysql              |
| performance_schema |
| ray                |
| sys                |
+--------------------+
6 rows in set (0.00 sec)

备份到远程机器
远程流试压缩备份

./innobackupex --defaults-file=/mysql/my3306/my.cnf --no-timestamp --user raybak --password raybak --stream=tar /tmp | gzip | ssh root@192.168.0.1 "cat - > /home/full20221208bak.tar.gz"
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值