将CDB实例的物理备份恢复到自建的mysql数据库
CDB实例:cdb-fopx6fXX
云服务器:用于恢复CDB的物理备份
如下是CDB控制台可以看到的实例中存在的数据库
【注意:CDB的默认备份方式为逻辑备份,但是如果数据量特别大,逻辑备份的恢复速度比较慢】
[root@VM_35_215_centos ~]# mkdir -p /data/mysql/mysql_3310/{data,log,tmp}
[root@VM_35_215_centos ~]# ll /data/mysql/mysql_3310/
total 12
drwxr-xr-x 2 root root 4096 Oct 30 18:18 data
drwxr-xr-x 2 root root 4096 Oct 30 18:18 log
drwxr-xr-x 2 root root 4096 Oct 30 18:18 tmp
[root@VM_35_215_centos xtrabackupfile]# wget 'http://sh.dl.cdb.tencentyun.com:xxxxx/a789e231970810651239e2c2fd18b128?appid=1251123904&time=1540900309&sign=NRXQWiNJqtICXGlLpMR2w%2Fs7J5I%3D'
[root@VM_35_215_centos xtrabackupfile]# tar xf a789e231970810651239e2c2fd18b128\?appid\=1251123904\&time\=1540900309\&sign\=NRXQWiNJqtICXGlLpMR2w%2Fs7J5I\=
[root@VM_35_215_centos xtrabackupfile]# ll
drwxr-xr-x 40 root root 4096 Oct 30 19:49 cdb-fopx6fXX_20181030194849
[root@VM_35_215_centos cdb-fopx6f6v_20181030194849]# ll
total 124332
........(此处省略N行)
drwxr-x--- 2 root root 4096 Oct 30 19:48 along_bak
drwxr-x--- 2 root root 12288 Oct 30 19:49 aws
-rw-r----- 1 root root 419 Oct 30 19:49 backup-my.cnf
drwxr-x--- 2 root root 4096 Oct 30 19:49 ceshi
drwxr-x--- 2 root root 4096 Oct 30 19:48 ceshi2
drwxr-x--- 2 root root 4096 Oct 30 19:49 ceshi2_bak
drwxr-x--- 2 root root 4096 Oct 30 19:49 ceshi_bak
drwxr-x--- 2 root root 4096 Oct 30 19:49 congshao
drwxr-x--- 2 root root 4096 Oct 30 19:49 daxie
drwxr-x--- 2 root root 4096 Oct 30 19:48 DAXIE
........(此处省略N行)
-rw-r----- 1 root root 79691776 Oct 30 19:49 ibdata1
-rw-r----- 1 root root 12582912 Oct 30 19:49 ibtmp1
drwxr-x--- 2 root root 4096 Oct 30 19:49 liujian
drwxr-x--- 2 root root 4096 Oct 30 19:48 mysql
drwxr-x--- 2 root root 4096 Oct 30 19:49 performance_schema
drwxr-x--- 2 root root 4096 Oct 30 19:49 shaocong
........(此处省略N行)
-rw-r----- 1 root root 26214400 Oct 30 19:49 undo001
-rw-r----- 1 root root 118 Oct 30 19:49 xtrabackup_binlog_info
-rw-r--r-- 1 root root 28 Oct 30 19:49 xtrabackup_binlog_pos_innodb
-rw-r----- 1 root root 376 Oct 30 19:49 xtrabackup_cdb_result
-rw-r----- 1 root root 121 Oct 30 19:49 xtrabackup_checkpoints
-rw-r----- 1 root root 810 Oct 30 19:49 xtrabackup_info
-rw-r----- 1 root root 8388608 Oct 30 19:49 xtrabackup_logfile
-rw-r----- 1 root root 156 Oct 30 19:49 xtrabackup_slave_info
从物理备份文件中可以看到有如上的一些以xtrabackup开头的一些文件
xtrabackup_checkpoints 记录备份完成时检查点的lsn号和该备份文件类型,full-backuped全量备份
xtrabackup_binlog_info 记录二进制日志和偏移量,若开启gtid,还会记录gtid位置,为在线搭建从库做准备
xtrabackup_info 记录备份详细信息,如备份命令、开始结束时间、版本等
[root@VM_35_215_centos xtrabackupfile]# mv cdb-fopx6f6v_20181030194849/ /data/mysql/mysql_3310/data
由于是多实例部署,所以使用了mysqld_multi统一管理,如果是单实例的可忽略配置文件中[mysqld_multi]的设置
[root@VM_35_215_centos ~]# chown -R mysql:mysql /data/mysql/mysql_3310/
[root@VM_35_215_centos ~]# vim /etc/my.cnf
[mysqld_multi]
user=root
pass=XXXXXX
mysqld=/usr/local/mysql/bin/mysqld_safe
mysqladmin=/usr/local/mysql/bin/mysqladmin
log=/data/mysql/mysqld_multi.log
[mysqld]
#skip-grant-tables
user=mysql
basedir = /usr/local/mysql
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
max_allowed_packet = 16M
character_set_server = utf8mb4
[mysqld3310]
#skip-grant-tables
mysqld=mysqld
mysqladmin=mysqladmin
datadir=/data/mysql/mysql_3310/data/
socket=/tmp/mysql3310.sock
port=3310
server_id=3310
log-output=file
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /data/mysql/mysql_3310/log/slow.log
log-error = /data/mysql/mysql_3310/log/error.log
binlog_format = mixed
log-bin = /data/mysql/mysql_3310/log/mysql3310.bin
secure_file_priv=/tmp
gtid-mode = ON
enforce-gtid-consistency = ON
log-slave-updates = ON
query_cache_size=0
query_cache_type=1
[root@VM_35_215_centos ~]# mysqld_multi start 3310
[root@VM_35_215_centos ~]# mysqld_multi report 3310
Reporting MySQL servers
MySQL server from group: mysqld3310 is running
启动成功
[root@VM_35_215_centos ~]# mysql -u root -p -S /tmp/mysql3310.sock
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[mysqld3310]
skip-grant-tables
[root@VM_35_215_centos ~]# mysqld_multi start
[root@VM_35_215_centos ~]# mysqld_multi report 3310
Reporting MySQL servers
MySQL server from group: mysqld3310 is running
root@ [(none)]>update mysql.user set password=password('qcloud@2018') where user='root';
Query OK, 5 rows affected, 1 warning (0.05 sec)
Rows matched: 5 Changed: 5 Warnings: 1
至此通过CDB物理备份恢复数据库全部完成;
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。