Mysql 物理备份Xtrabackup
祖仙教小凡仙 海鲨数据库架构师
这是Percona公司出品的MYSQL物理备份工具,对大数据量的MYSQL挺不错的.以前Percona出品的叫Innobackupex工具,以前玩过次,感觉贼不好装,因为版本问题发生冲突. 官网下载 https://HdhCmsTestpercona测试数据/downloads/Percona-XtraBackup-LATEST/# 有各种平台,各种版本的, 我选择 Linux 通用版,发现也有好多选项, 有500MB和20MB。 特烦! 无论是500MB或者20MB版本都无法下载,因为国内没有镜像网站! 后来朋友给了RPM版,我又从网上找到RPM下载地址
wget https://HdhCmsTestpercona测试数据/downloads/XtraBackup/Percona-XtraBackup-80.0.4/binary/redhat/7/x86_64/percona-xtrabackup-80-8.0.4-1.el7.x86_64.rpm yum install -y percona-xtrabackup-80-8.0.4-1.el7.x86_64.rpm
下载到哪里?
[root@localhost tool_install]# find / -name xtrabackup /usr/bin/xtrabackup /usr/lib64/xtrabackup
看下有啥?
[root@localhost tool_install]# cd /usr/bin/ [root@localhost bin]# ll *backup* -rwxr-xr-x. 1 root root 15696 6月 10 2014 db_hotbackup -rwxr-xr-x. 1 root root 36856 6月 10 2014 idevicebackup -rwxr-xr-x. 1 root root 45200 6月 10 2014 idevicebackup2 -rwxr-xr-x. 1 root root 15408 6月 18 2014 ntdbbackup -rwxr-xr-x 1 root root 51408904 12月 6 2018 xtrabackup
从时间上看就一个XTRABACKUP命令 另外个目录就没啥
/usr/lib64/xtrabackup/plugin [root@localhost plugin]# ll 总用量 304 -rwxr-xr-x 1 root root 149560 12月 6 2018 keyring_file.so -rwxr-xr-x 1 root root 158504 12月 6 2018 keyring_vault.so
那么我们启动MYSQL吧!
[root@localhost u01]# service mysqld start Starting MySQL....... SUCCESS!
查看MYSQL目录
[root@localhost plugin]# ps -ef | grep mysqld root 29538 1 0 22:05 pts/0 0 /bin/sh /u01/mysql/mysql8020debug/bin/mysqld_safe --datadir=/u01/mysql/mysql8020debug/data --pid-file=/u01/mysql/mysql8020debug/data/localhost.localdomain.pid mysql 29861 29538 1 22:05 pts/0 00:00:05 /u01/mysql/mysql8020debug/bin/mysqld --basedir=/u01/mysql/mysql8020debug --datadir=/u01/mysql/mysql8020debug/data --plugin-dir=/u01/mysql/mysql8020debug/lib/plugin --user=mysql --log-error=/u01/mysql/mysql8020debug/mysql-error.log --pid-file=/u01/mysql/mysql8020debug/data/localhost.localdomain.pid --socket=/tmp/mysql.sock --port=3306
进入MYSQL目录看有啥?
[root@localhost ~]# cd /u01/mysql/mysql8020debug/ [root@localhost mysql8020debug]# [root@localhost mysql8020debug]# ll 总用量 1024 drwxr-xr-x. 2 mysql dba 4096 7月 10 2020 bin drwxrwxr-x 7 mysql mysql 4096 1月 27 22:06 data drwxr-xr-x. 2 mysql dba 4096 7月 10 2020 docs drwxr-xr-x. 3 mysql dba 4096 7月 10 2020 include drwxr-xr-x. 6 mysql dba 4096 7月 10 2020 lib -rw-r--r--. 1 mysql dba 404604 3月 26 2020 LICENSE -rw-r--r--. 1 mysql dba 104198 3月 26 2020 LICENSE.router -rw-r--r--. 1 mysql dba 404604 3月 26 2020 LICENSE-test -rwxrwxr-x 1 mysql mysql 28 7月 19 2020 log_mysqlc_by_root.sh drwxr-xr-x. 4 mysql dba 4096 7月 10 2020 man -rw-r--r-- 1 mysql dba 689 12月 12 19:11 my.cnf -rw-r-----. 1 mysql dba 55618 1月 27 22:06 mysql-error.log -rwxr-xr-x 1 mysql dba 189 7月 19 2020 mysql_initdb.sh drwxr-xr-x. 10 mysql dba 4096 7月 10 2020 mysql-test -rw-r--r--. 1 mysql dba 687 3月 26 2020 README -rw-r--r--. 1 mysql dba 700 3月 26 2020 README.router -rw-r--r--. 1 mysql dba 687 3月 26 2020 README-test drwxrwxr-x. 2 mysql dba 4096 7月 10 2020 run drwxr-xr-x. 28 mysql dba 4096 7月 10 2020 share drwxr-xr-x. 2 mysql dba 4096 7月 11 2020 support-files drwxr-xr-x. 3 mysql dba 4096 7月 10 2020 var
创建备份目录
[root@localhost mysql8020debug]# mkdir backup
完全备份数据库命令
xtrabackup --defaults-file=/u01/mysql/mysql8020debug/my.cnf --user=root --password=123456 --backup --target-dir=/u01/mysql/mysql8020debug/backup ## --host= --port=
基本参数说明
--defaults-file ##mysql配置文件 --user ##执行备份的MYSQL用户 --password= ##对应用户的密码 --backup --target-dir ##这个命令组合才对 中间隔个空格 在帮助里是看不到组合的 --host= ##默认是本地实例,指定的话一般是远程IP地址 --port= ##默认端口3306,如果是别的自然要明确指出
备份出错
xtrabackup: recognized server arguments: --datadir=/u01/mysql/mysql8020debug/data xtrabackup: recognized client arguments: --port=3306 --socket=/tmp/mysql.sock --user=root --password=* --backup=1 --target-dir=/u01/mysql/mysql8020debug/backup xtrabackup version 8.0.4 based on MySQL server 8.0.13 Linux (x86_64) (revision id: c2c0777) 210127 22:48:47 version_check Connecting to MySQL server with DSN 'dbi:mysql:;mysql_read_default_group=xtrabackup;port=3306;mysql_socket=/tmp/mysql.sock' as 'root' (using password: YES). Failed to connect to MySQL server: DBI connect(';mysql_read_default_group=xtrabackup;port=3306;mysql_socket=/tmp/mysql.sock','root',...) failed: Authentication plugin 'caching_sha2_password' cannot be loaded: /usr/lib64/mysql/plugin/caching_sha2_password.so: 无法打开共享对象文件: 没有那个文件或目录 at - line 1535. 210127 22:48:48 Connecting to MySQL server host: localhost, user: root, password: set, port: 3306, socket: /tmp/mysql.sock Using server version 8.0.20-debug xtrabackup: uses posix_fadvise(). xtrabackup: cd to /u01/mysql/mysql8020debug/data xtrabackup: open files limit requested 0, set to 1024 xtrabackup: using the following InnoDB configuration: xtrabackup: innodb_data_home_dir = . xtrabackup: innodb_data_file_path = ibdata1:12M:autoextend xtrabackup: innodb_log_group_home_dir = ./ xtrabackup: innodb_log_files_in_group = 2 xtrabackup: innodb_log_file_size = 50331648 Number of pools: 1 Unknown redo log format (4). Please follow the instructions at http://dev.mysql测试数据/doc/refman/8.0/en/ upgrading-downgrading.html.
这里涉及两个错误 1个是密码验证, 另外一个是REDO 格式
第一个错误FIX:
mysql> select host,user,plugin from user; +------+------------------+-----------------------+ | host | user | plugin | +------+------------------+-----------------------+ | % | mysql.infoschema | caching_sha2_password | | % | mysql.session | caching_sha2_password | | % | mysql.sys | caching_sha2_password | | % | root | caching_sha2_password | +------+------------------+-----------------------+ 4 rows in set (0.00 sec) mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456'; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.01 sec) mysql> select host,user,plugin from user; +------+------------------+-----------------------+ | host | user | plugin | +------+------------------+-----------------------+ | % | mysql.infoschema | caching_sha2_password | | % | mysql.session | caching_sha2_password | | % | mysql.sys | caching_sha2_password | | % | root | mysql_native_password | +------+------------------+-----------------------+ 4 rows in set (0.00 sec) mysql>
第二个错误FIX: 原是,当前版本的 xtrabackup 不支持 MySQL 8.0.20 需要升级 xtrbackup 到8.0.13即可。
[root@localhost tool_install]# xtrabackup -? xtrabackup version 8.0.4 based on MySQL server 8.0.13 Linux (x86_64) (revision id: c2c0777) [root@localhost tool_install]# rpm -qa | grep xtrabackup percona-xtrabackup-80-8.0.4-1.el7.x86_64 [root@localhost tool_install]# rpm -e percona-xtrabackup-80-8.0.4-1.el7.x86_64 wget https://HdhCmsTestpercona测试数据/downloads/XtraBackup/Percona-XtraBackup-80.14.1/binary/redhat/7/x86_64/percona-xtrabackup-80-8.0.14-1.el7.x86_64.rpm [root@localhost tool_install]# rpm -ivh percona-xtrabackup-80-8.0.14-1.el7.x86_64.rpm 警告:percona-xtrabackup-80-8.0.14-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID 8507efa5: NOKEY 准备中... ################################# [100%] 正在升级/安装... 1:percona-xtrabackup-80-8.0.14-1.el################################# [100%]
继续备份再遇错误:
210127 23:07:19 Finished backing up non-InnoDB tables and files 210127 23:07:19 Executing FLUSH NO_WRITE_TO_BINLOG BINARY LOGS 210127 23:07:19 Selecting LSN and binary log position from p_s.log_status Error: failed to fetch query result SELECT server_uuid, local, replication, storage_engines FROM performance_schema. log_status: Access denied; you need (at least one of) the BACKUP_ADMIN privilege(s) for this operation
需要权限,简单给它就是!
mysql> grant BACKUP_ADMIN on *.* to 'root'@'%'; Query OK, 0 rows affected (0.01 sec) mysql> flush privileges; Query OK, 0 rows affected (0.01 sec)
再遇错误:
210127 23:10:31 Connecting to MySQL server host: localhost, user: root, password: set, port: 3306, socket: /tmp/mysql.sock xtrabackup: Redo Log Archiving is not set up. xtrabackup: Can't create/write to file '/u01/mysql/mysql8020debug/backup/xtrabackup_logfile' (OS errno 17 - File exists) xtrabackup: error: failed to open the target stream for 'xtrabackup_logfile'.
大意是xtrabackup_logfile文件存在,好吧我们删除已经备份的文件.
[root@localhost ~]# cd /u01/mysql/mysql8020debug/backup/ [root@localhost backup]# ll 总用量 57364 drwxr-x--- 2 root root 4096 1月 27 23:07 bookstore -rw-r----- 1 root root 12582912 1月 27 23:07 ibdata1 drwxr-x--- 2 root root 4096 1月 27 23:07 mysql -rw-r----- 1 root root 25165824 1月 27 23:07 mysql.ibd drwxr-x--- 2 root root 4096 1月 27 23:07 performance_schema drwxr-x--- 2 root root 4096 1月 27 23:07 sys -rw-r----- 1 root root 10485760 1月 27 23:07 undo_001 -rw-r----- 1 root root 10485760 1月 27 23:07 undo_002 -rw-r----- 1 root root 2048 1月 27 23:07 xtrabackup_logfile
删除后再备份,就成功了
210127 23:12:36 Backup created in directory '/u01/mysql/mysql8020debug/backup/' MySQL binlog position: filename 'binlog.000027', position '156' 210127 23:12:36 [00] Writing /u01/mysql/mysql8020debug/backup/backup-my.cnf 210127 23:12:36 [00] ...done 210127 23:12:36 [00] Writing /u01/mysql/mysql8020debug/backup/xtrabackup_info 210127 23:12:36 [00] ...done xtrabackup: Transaction log of lsn (18216058) to (18216088) was copied. 210127 23:12:37 completed OK! [root@localhost backup]# ll 总用量 57396 -rw-r----- 1 root root 475 1月 27 23:12 backup-my.cnf -rw-r----- 1 root root 156 1月 27 23:12 binlog.000027 -rw-r----- 1 root root 16 1月 27 23:12 binlog.index drwxr-x--- 2 root root 4096 1月 27 23:12 bookstore -rw-r----- 1 root root 3578 1月 27 23:12 ib_buffer_pool -rw-r----- 1 root root 12582912 1月 27 23:12 ibdata1 drwxr-x--- 2 root root 4096 1月 27 23:12 mysql -rw-r----- 1 root root 25165824 1月 27 23:12 mysql.ibd drwxr-x--- 2 root root 4096 1月 27 23:12 performance_schema drwxr-x--- 2 root root 4096 1月 27 23:12 sys -rw-r----- 1 root root 10485760 1月 27 23:12 undo_001 -rw-r----- 1 root root 10485760 1月 27 23:12 undo_002 -rw-r----- 1 root root 18 1月 27 23:12 xtrabackup_binlog_info -rw-r----- 1 root root 95 1月 27 23:12 xtrabackup_checkpoints -rw-r----- 1 root root 547 1月 27 23:12 xtrabackup_info -rw-r----- 1 root root 2560 1月 27 23:12 xtrabackup_logfile -rw-r----- 1 root root 39 1月 27 23:12 xtrabackup_tablespaces
查看几个备份的XTRABACKUP_*
[root@localhost backup]# cat xtrabackup_info uuid = 1674f412-60b2-11eb-966c-080027d6e4bc name = tool_name = xtrabackup tool_command = --defaults-file=/u01/mysql/mysql8020debug/my.cnf --user=root --password=... --backup --target-dir=/u01/mysql/mysql8020debug/backup tool_version = 8.0.14 ibbackup_version = 8.0.14 server_version = 8.0.20-debug start_time = 2021-01-27 23:12:31 end_time = 2021-01-27 23:12:36 lock_time = 2 binlog_pos = filename 'binlog.000027', position '156' innodb_from_lsn = 0 innodb_to_lsn = 18216058 partial = N incremental = N format = file compressed = N encrypted = N [root@localhost backup]# cat xtrabackup_binlog_info binlog.000027 156 [root@localhost backup]# cat xtrabackup_checkpoints backup_type = full-backuped from_lsn = 0 to_lsn = 18216058 last_lsn = 18216078 flushed_lsn = 0 [root@localhost backup]# cat xtrabackup_tablespaces {"version":3,"external_tablespaces":[]}[root@localhost backup]#
查看更多关于Mysql 物理备份Xtrabackup的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did127960