标签:数据库表 server version 数据表 版本号 xtrabackup
Xtrabackup之备份与还原
Xtrabackup是percona的一个开源项目,可以热备份innodb,XtraDB,和MyISAM(会锁表),可以看做是mysql商业备份工具InnoDB Hotbackup的免费替代品。
①xtrabackup只能备份InnoDB和XtraDB两种数据库表,支持在线热备份,可以在不加锁的情况下备份Innodb数据表,不过此工具不能操作MyiSAM引擎表
②innobackupex是一个脚本封装,封装了xtrabackup,能同时处理Innodb和MyISAM,但在处理MyISAM时需要加一个读锁。
1. 准备工作
由于mysql版本号不同可能导致备份不成功,一次请尽量使用最新的版本,最新的版本会兼容旧版本。
xtrabackup版本:xtrabackup version 2.2.11 based on MySQL server 5.6.24 Linux (x86_64) (revision id: )
mysql版本:Server version: 5.5.5-10.0.15-MariaDB MariaDB Server
xtrabakcup官网下载地址:
https://www.percona.com/software/mysql-database/percona-xtrabackup
mariadb官网下载地址:
https://downloads.mariadb.org/
2. 安装xtrabakcup包
安装xtrabackup需要的依赖包:
yum install perl-DBI perl-DBD-MySQL perl-Time-HiRes perl-IO-Socket-SSL perl perl-devel
安装xtrabakcup:
rpm -ivh percona-xtrabackup-2.2.11-1.el6.x86_64.rpm
3. 全库备份命令:
innobackupex --defaults-file=/etc/my.cnf --user=root --password=cisco /home/mysql/ --parallel=4
[root@iZ23zynkag6Z 2016-04-21_13-59-35]# ll total 77876 -rw-r--r-- 1 root root 358 Apr 21 13:59 backup-my.cnf drwx------ 2 root root 4096 Apr 21 13:59 cisco1 drwx------ 2 root root 4096 Apr 21 13:59 cisco2 drwxr-xr-x 2 root root 4096 Apr 21 13:59 cisco3 drwxr-xr-x 2 root root 4096 Apr 21 13:59 cisco4 drwxr-xr-x 2 root root 4096 Apr 21 13:59 cisco5 -rw-r----- 1 root root 79691776 Apr 21 13:59 ibdata1 drwx------ 2 root root 4096 Apr 21 13:59 mysql drwxr-xr-x 2 root root 4096 Apr 21 13:59 performance_schema drwxr-xr-x 2 root root 4096 Apr 21 13:59 test -rw-r--r-- 1 root root 31 Apr 21 13:59 xtrabackup_binlog_info -rw-r----- 1 root root 89 Apr 21 13:59 xtrabackup_checkpoints -rw-r--r-- 1 root root 644 Apr 21 13:59 xtrabackup_info -rw-r----- 1 root root 2560 Apr 21 13:59 xtrabackup_logfile
3. 恢复数据库:
下面以mariadb-10.0.15还原为例进行说明:
mariadb数据库之前的安装目录为: /usr/local/mysql/
数据目录 /usr/local/mysql/data
进入备份文件目录:
cd /mysqlbackup/2016-04-21_13-59-35 [root@iZ23zynkag6Z 2016-04-21_13-59-35]# ll total 129708 -rw-rw---- 1 mysql mysql 16384 Apr 21 14:41 aria_log.00000001 -rw-rw---- 1 mysql mysql 52 Apr 21 14:41 aria_log_control -rwxr-xr-x 1 mysql mysql 402 Apr 21 14:28 backup-my.cnf drwxr-xr-x 2 mysql mysql 4096 Apr 21 13:59 cisco1 drwxr-xr-x 2 mysql mysql 4096 Apr 21 13:59 cisco2 drwxr-xr-x 2 mysql mysql 4096 Apr 21 13:59 cisco3 drwxr-xr-x 2 mysql mysql 4096 Apr 21 13:59 cisco4 drwxr-xr-x 2 mysql mysql 4096 Apr 21 13:59 cisco5 -rwxr-xr-x 1 mysql mysql 79691776 Apr 21 14:41 ibdata1 -rw-rw---- 1 mysql mysql 50331648 Apr 21 14:29 ib_logfile1 -rwxr-xr-x 1 mysql mysql 69853 Apr 21 14:41 iZ23zynkag6Z.err -rw-rw---- 1 mysql mysql 0 Apr 21 14:29 multi-master.info drwxr-xr-x 2 mysql mysql 4096 Apr 21 13:59 mysql drwxr-xr-x 2 mysql mysql 4096 Apr 21 13:59 performance_schema drwxr-xr-x 2 mysql mysql 4096 Apr 21 13:59 test -rwxr-xr-x 1 mysql mysql 31 Apr 21 13:59 xtrabackup_binlog_info -rwxr-xr-x 1 mysql mysql 89 Apr 21 13:59 xtrabackup_checkpoints -rwxr-xr-x 1 mysql mysql 644 Apr 21 13:59 xtrabackup_info -rwxr-xr-x 1 mysql mysql 2654208 Apr 21 14:41 xtrabackup_logfile
恢复备份文件:
innobackupex --defaults-file=./backup-my.cnf --apply-log ./
系统显示 innobackupex: completed OK!,则数据恢复成功。
修改备份文件中的配置文件backup-my.cnf: #innodb_page_size #innodb_log_block_size注释,然后添加datadir为备份的文件目录:
# The MySQL server [mysqld] innodb_checksum_algorithm=innodb innodb_log_checksum_algorithm=innodb innodb_data_file_path=ibdata1:12M:autoextend innodb_log_files_in_group=2 innodb_log_file_size=50331648 #innodb_page_size=16384 #innodb_log_block_size=512 innodb_undo_directory=. innodb_undo_tablespaces=0 datadir=/mysqlbackup/2016-04-21_13-59-35/
修改文件属性:
chmod -R 755 /mysqlbackup/ chown -R mysql.mysql /mysqlbakcup/
重新安装mysql,指定datadir目录
./scripts/mysql_install_db --user=mysql --datadir=/mysqlbackup/
启动mysqld服务:
/usr/local/mysql/bin/mysqld_safe --defaults-file=/mysqlbackup/2016-04-21_13_59_35/backup-my.cnf --user=mysql &
连接mysql服务,查看数据是否正常。
[root@iZ23zynkag6Z mysql]# /usr/local/mysql/bin/mysqld_safe /mysqlbackup/2016-04-21_13_59_35/backup-my.cnf --user=mysql & [1] 26625 [root@iZ23zynkag6Z mysql]# 160421 15:27:22 mysqld_safe Logging to ‘/home/mysql//iZ23zynkag6Z.err‘. 160421 15:27:22 mysqld_safe Starting mysqld daemon with databases from /home/mysql/
---------------------------------其他相关说明-----------------------------------------------------
增量备份待补充。。。
本文出自 “少犟” 博客,请务必保留此出处http://xushaojie.blog.51cto.com/6205370/1766275
标签:数据库表 server version 数据表 版本号 xtrabackup
原文地址:http://xushaojie.blog.51cto.com/6205370/1766275