阿里云有相关文档,如:RDS for MySQL 物理备份文件恢复到自建数据库
本文主要以该文档为主题,记录恢复过程。
下载备份数据
登录 RDS管理控制台 左侧导航栏进入 备份恢复 点击 数据备份 下载对应备份文件。
wget -c '<数据备份文件外网下载地址>' -O <自定义文件名>.tar.gz
恢复备份数据
1.解压
tar -izxvf <数据备份文件名>.tar.gz -C /home/mysql/data
2.工具
yum -y install perl-devel perl-Time-HiRes perl-DBD-MySQL libev rpm -ivh percona-xtrabackup-24-2.4.12-1.el6.x86_64.rpm
3.恢复
innobackupex --defaults-file=/home/mysql/data/backup-my.cnf --apply-log /home/mysql/data
当执行该步骤是报了以下错误
InnoDB: Log file ./ib_logfile1 is of different size 1572864000 bytes than other log files 8384675840 bytes! InnoDB: Plugin initialization aborted with error Generic error xtrabackup: innodb_init(): Error occured.
原因: innodb_log_file_size 本地值和备份值不统一
解决:删除 ib_logfile1 文件,重新执行命令
InnoDB: Shutdown completed; log sequence number 4470207131688 181220 12:18:43 completed OK!
关联数据库
使用backup-my.cnf替换本地my.cnf文件
mv /etc/my.cnf my.cnf.bak cp /home/mysql/data/backup-my.cnf /etc/my.cnf
为避免版本问题,需修改backup-my.cnf文件注释以下参数
#innodb_fast_checksum #innodb_page_size #innodb_log_block_size
如果本地使用的是MyISAM引擎,和阿里云的InnoDB不兼容,需要多注释掉如下参数并增加skip-grant-tables参数:
#innodb_log_checksum_algorithm=strict_crc32 #redo_log_version=1 skip-grant-tables
修改文件属主
chown -R mysql:mysql /home/mysql/data
如果不修改属主可能会无法启动mysql,报如下错误
InnoDB: The error means mysqld does not have the access rights to InnoDB: the directory. InnoDB: File name ./ib_logfile0 InnoDB: File operation call: 'open'. InnoDB: Cannot continue operation.
本文链接:https://jeff.xin/post/108.html
--EOF--
Comments
发表评论:
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。