UCloud MySQL innodbackup物理备份还原到本地
MySQL安装教程推荐:https://www.starcto.com/mysql/305.html
1、下载物理备份文件
https://console.ucloud.cn/udb/sql?key=backup_list
[root@starctonode1 ~]# mkdir /data/mysql [root@starctonode1 ~]# cd /data/mysql/ [root@starctonode1 mysql]# wget "下载URL" -O backup_20230131154221.xbstream
2、解包备份文件
(1)下载与解压qpress工具:qpress-11-linux-x64.tar
[root@starctonode1 ~]# tar -xf qpress-11-linux-x64.tar -C /usr/local/bin [root@starctonode1 ~]# source /etc/profile
(2)安装xtrabackup工具
[root@starctonode1 ~]# yum install https://repo.percona.com/yum/percona-release-latest.noarch.rpm -y [root@starctonode1 ~]# yum install percona-xtrabackup-24 -y
(3)解包.xbstream文件和解析解包后/data/mysql目录下所有以.qp结尾的文件
[root@starctonode1 ~]# xbstream -x -C /data/mysql < /root/backup_20230131154221.xbstream [root@starctonode1 ~]# xtrabackup --decompress --target-dir=/data/mysql --remove-original xtrabackup: recognized server arguments: --datadir=/var/lib/mysql xtrabackup: recognized client arguments: --decompress=1 --target-dir=/data/mysql --remove-original=1 xtrabackup version 2.4.27 based on MySQL server 5.7.40 Linux (x86_64) (revision id: aae8e82) 230131 16:11:46 completed OK!
注意:/data/mysql 为之前存储备份文件的目标目录 ,您可根据实际情况替换为实际路径。Percona Xtrabackup 在2.4.6及以上版本中才支持 --remove-original 选项。xtrabackup 默认在解压缩时不删除原始的压缩文件,若需解压完删除原始的压缩文件,可在上面的命令中加上 --remove-original 参数。
3、Prepare备份文件
备份解压出来之后,执行如下命令进行 apply log 操作。
[root@starctonode1 ~]# xtrabackup --prepare --target-dir=/data/mysql
4、修改配置文件
由于存在的版本问题,请将解压文件 backup-my.cnf 中如下参数进行注释。
innodb_checksum_algorithm innodb_log_checksum_algorithm innodb_fast_checksum innodb_page_size innodb_log_block_size redo_log_version
[root@starctonode1 ~]# vim /data/mysql/backup-my.cnf # The MySQL server [mysqld] # 备份配置文件部分 #innodb_checksum_algorithm=crc32 #innodb_log_checksum_algorithm=strict_crc32 #innodb_fast_checksum=false #innodb_page_size=16384 #innodb_log_block_size=512 #redo_log_version=1 innodb_undo_directory=./ innodb_undo_tablespaces=0 server_id=169410562 innodb_data_file_path=ibdata1:100M:autoextend innodb_log_files_in_group=2 innodb_log_file_size=1073741824 server_uuid=c1a9f473-a138-11ed-9990-525400ca794f master_key_id=0 # 默认配置文件部分 datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock symbolic-links=0 log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid
注意:修改配置文件后,如果启动异常,则使用MySQL默认配置文件,无需使用备份中的配置文件即可。
5、修改文件属性
[root@starctonode1 ~]# cp -r /data/mysql/* /var/lib/mysql [root@starctonode1 ~]# chown -R mysql:mysql /var/lib/mysql
6、启动 mysqld 进程并登录验证
[root@starctonode1 ~]# systemctl restart mysqld.service [root@starctonode1 ~]# mysql -uroot -pUcloudcn 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 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 | | mysql | | performance_schema | | school | | sys | +--------------------+ 5 rows in set (0.00 sec) mysql> use school Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> show tables; +------------------+ | Tables_in_school | +------------------+ | COURSE | | SCORE | | STUDENT | | TEACHER | +------------------+ 4 rows in set (0.00 sec) mysql> select * from COURSE; +-------+-----------------+-----+ | CNO | CNAME | TNO | +-------+-----------------+-----+ | 3-105 | 计算机导论 | 825 | | 3-245 | 操作系统 | 804 | | 6-166 | 数据电路 | 856 | | 9-888 | 高等数学 | 100 | +-------+-----------------+-----+ 4 rows in set (0.00 sec)
注:如上查看还原成功。
作者:UStarGao
链接:https://www.starcto.com/mysql/315.html
来源:STARCTO
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
UCloud云平台推荐
随便看看
- 2021-06-23 Linux性能异常经典案例分析之包量吞吐
- 2021-10-08 Microsoft SQL Server数据迁移解决方案
- 2021-04-24Zabbix-Server实现监控主机服务器
- 2021-08-16Elasticsearch 7.7.0容器化部署
- 2024-09-06基于UCloud UDNS产品和NLB产品实现kafka多节点调度