您好,登录后才能下订单哦!
这期内容当中小编将会给大家带来有关xtrabackup备份工具命令如何进行单库增量备份还原,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。
Innobackupex 参数解释:
--defaults-file=[MY.CNF]该选项传递给xtrabackup子进程,从指定文件读取缺省选项
--apply-log 从备份恢复。
--redo-only 该选项强制跳过rollback阶段,只进行redo。这是有必要使用的,如果备份后,要使用增量改变的。
--copy-back 从备份目录拷贝数据和索引文件到datadir目录
--remote-host=HOSTNAME备份到远程主机上,使用ssh
--stream=[tar|cpio(notimplemented)] 指定备份标准输出格式
--tmpdir=DIRECTORY默认与tmpdir相同。使用—remote-host或—stream参数后,传输日志文件将存放在临时目录下
--use-memory=MB选项传递给xtrabackup子进程。恢复使用内存大小
--parallel=NUMBER-OF-THREADS选项传递给xtrabackup子进程,指定数据传输线程总数。默认为1
--throttle=IOS选项传递给xtrabackup子进程,限制IO线程数量
--sleep=MS 选项传递给xtrabackup子进程。每拷贝1MB数据暂停多少MS时间
--compress[=LEVEL]选项传递给xtrabackup子进程。压缩级别在0-9.1快速压缩,9最佳压缩,0不压缩。默认为1.
--include=REGEXP选项传递给xtrabackup子进程。使用正则进行匹配
--databases=LIST指定备份数据库
--tables-file=FILE
--uncompress选项传递给xtrabackup子进程。对压缩过的InnoDB数据文件不进行压缩
--export 仅使用于prepare选项。选项传递给xtrabackup子进程。
--user=NAME
--password=WORD
--host=HOST
--port=PORT
--slave-info 备份复制从服务端,主从信息记录在ibbackup_slave_info文件中
--socket=SOCKET
--no-timestamp不在备份根目录下创建以当前时间戳为名称的新的备份目录
--ibbackup=IBBACKUP-BINARYibbackup二进制路径
--no-lock 禁止表级锁。全部是InnoDB引擎表和不关系二进制日志位置下使用
--scpopt=SCP-OPTIONS指定scp参数
innobackupex单库增量恢复
[root@mini1 ~]# mkdir -p /opt/mysqlbackup/{full,inc}
#完全备份
[root@mini1 ~]# innobackupex --user=root --password=123456 --include=test /opt/mysqlbackup/full/
mysql> select * from test.t1;
+----+------+
| id | name |
+----+------+
| 1 | tom1 |
| 2 | tom1 |
+----+------+
#插入数据
mysql> insert into test.t1(name) values('tom2');
#增量备份1
[root@mini1 ~]# innobackupex --user=root --password=123456 --include=test --incremental /opt/mysqlbackup/inc/ --incremental-basedir=/opt/mysqlbackup/full/2018-07-30_20-36-57/
#插入数据,添加新表
mysql> insert into test.t1(name) values('tom3');
mysql> create table test.t2(id int);
mysql> insert into test.t2 values(1);
mysql> select * from test.t2;
+------+
| id |
+------+
| 1 |
#增量备份2
[root@mini1 ~]# innobackupex --user=root --password=123456 --include=test --incremental /opt/mysqlbackup/inc/ --incremental-basedir=/opt/mysqlbackup/inc/2018-07-30_20-47-55/
[root@mini1 ~]# ls /opt/mysqlbackup/full
2018-07-30_20-36-57
[root@mini1 ~]# ls /opt/mysqlbackup/inc/
2018-07-30_20-47-55 2018-07-30_20-51-21
#删除数据库
mysql> drop database test;
[root@mini1 ~]# service mysqld stop
[root@mini1 ~]# cd /opt/mysqlbackup/full/2018-07-30_20-36-57/test/
[root@mini1 test]# ls
db.opt t1.frm t1.ibd
[root@mini1 ~]innobackupex --apply-log --redo-only /opt/mysqlbackup/full/2018-07-30_20-34-34/
[root@mini1 ~]innobackupex --apply-log --redo-only /opt/mysqlbackup/full/2018-07-30_20-34-34/ --incremental-dir=/opt/mysqlbackup/inc/2018-07-30_20-38-12/
[root@mini1 ~]innobackupex --apply-log --redo-only /opt/mysqlbackup/full/2018-07-30_20-34-34/ --incremental-dir=/opt/mysqlbackup/inc/2018-07-30_20-42-03/
[root@mini1 ~]innobackupex --apply-log --export /opt/mysqlbackup/full/2018-07-30_20-34-34/
[root@mini1 ~]cp -rf /opt/mysqlbackup/full/2018-07-30_20-34-34/* /usr/local/mysql/data/
[root@mini1 data]# service mysqld restart
mysql> select * from t1;
+----+------+
| id | name |
+----+------+
| 1 | tom1 |
| 2 | tom1 |
| 3 | tom1 |
| 4 | tom1 |
| 5 | tom1 |
| 6 | tom1 |
+----+------+
6 rows in set (0.00 sec)
mysql> select * from t2
-> ;
+------+
| id |
+------+
| 1 |
| 3 |
| 2 |
+------+
innobackupex备份多库
[root@mini1 full]# innobackupex --user=root --password=123456 --databases="test test1" /opt/mysqlbackup/full/
xtrabackup备份单个表
[root@mini1 ~]# mkdir -p /opt/mysqlbackup/{full,inc}
[root@mini1 ~]# mysql -uroot -p123456
mysql> use test
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| test |
| test1 |
+--------------------+
mysql> select * from test.t1;
+----+------+
| id | name |
+----+------+
| 1 | tom1 |
| 2 | tom1 |
+----+------+
[root@mini1 ~]# xtrabackup --user=root --password=123456 --backup --target-dir=/opt/mysqlbackup/full/full_$(date +%F_%H%M%S) --databases="test"
mysql> insert into test.t1(name) values('tom1');
[root@mini1 ~]# xtrabackup --user=root --password=123456 --backup --target-dir=/opt/mysqlbackup/inc/inc_$(date +%F_%H%M%S) --incremental-basedir=/opt/mysqlbackup/full/full_2018-07-30_204200/ --databases='test'
mysql> insert into test.t1(name) values('tom1');
mysql> insert into test.t2(name) values('tom1');
[root@mini1 ~]# xtrabackup --user=root --password=123456 --backup --target-dir=/opt/mysqlbackup/inc/inc_$(date +%F_%H%M%S) --incremental-basedir=/opt/mysqlbackup/inc/inc_2018-07-30_205007/ --databases='test'
mysql> drop table test.t1;
mysql> delete from test.t2 where id=1;
[root@mini1 ~]# xtrabackup --prepare --apply-log-only --target-dir=/opt/mysqlbackup/full/full_2018-07-30_204200/
[root@mini1 ~]# cat /opt/mysqlbackup/full/full_2018-07-30_204200/xtrabackup_checkpoints
backup_type = log-applied
from_lsn = 0
to_lsn = 2609032
last_lsn = 2609041
compact = 0
recover_binlog_info = 0
[root@mini1 ~]# xtrabackup --prepare --apply-log-only --target-dir=/opt/mysqlbackup/full/full_2018-07-30_204200/ --incremental-dir=/opt/mysqlbackup/inc/inc_2018-07-30_205007/
[root@mini1 ~]# xtrabackup --prepare --apply-log-only --target-dir=/opt/mysqlbackup/full/full_2018-07-30_204200/ --incremental-dir=/opt/mysqlbackup/inc/inc_2018-07-30_205157/
[root@mini1 ~]# xtrabackup --prepare --target-dir=/opt/mysqlbackup/full/full_2018-07-30_204200/
[root@mini1 ~]# cat /opt/mysqlbackup/full/full_2018-07-30_204200/xtrabackup_checkpoints
backup_type = full-prepared
from_lsn = 0
to_lsn = 2613778
last_lsn = 2613787
compact = 0
recover_binlog_info = 0
[root@mini1 ~]# service mysqld stop
[root@mini1 ~]# cd /opt/mysqlbackup/full/full_2018-07-30_204200/
[root@mini1 full_2018-07-30_204200]# rsync -rvt --exclude 'xtrabackup_checkpoints' --exclude 'xtrabackup_logfile' ./ /usr/local/mysql/data/
[root@mini1 full_2018-07-30_204200]# chown -R mysql:mysql /usr/local/mysql/
[root@mini1 full_2018-07-30_204200]# service mysqld start
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| t1 |
| t2 |
+----------------+
2 rows in set (0.00 sec)
mysql> select * from t1;
+----+------+
| id | name |
+----+------+
| 1 | tom1 |
| 2 | tom1 |
| 3 | tom1 |
| 4 | tom1 |
+----+------+
4 rows in set (0.00 sec)
mysql> select * from t2;
+----+------+
| id | name |
+----+------+
| 1 | tom1 |
| 2 | tom1 |
| 3 | tom1 |
+----+------+
3 rows in set (0.00 sec)
xtrabackup备份多库
[root@mini1 /]# xtrabackup --defaults-file=/etc/my.cnf --user=root --password=123456 --backup --target-dir=/opt/mysqlbackup/full/3 --databases='test test1'
mysql> insert into test.t1(name) values('tom1');
上述就是小编为大家分享的xtrabackup备份工具命令如何进行单库增量备份还原了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注亿速云行业资讯频道。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。