Heim  >  Artikel  >  Datenbank  >  使用Xtrabackup备份MySQL数据库-

使用Xtrabackup备份MySQL数据库-

WBOY
WBOYOriginal
2016-06-07 16:55:381180Durchsuche

mysqldump支持在线备份,不过是逻辑备份,效率比较差。xtrabackup是开源的MySQL备份工具,物理备份,效率很不错。下载编译好的二

mysqldump支持在线备份,,不过是逻辑备份,效率比较差。

xtrabackup是开源的MySQL备份工具,物理备份,效率很不错。
下载编译好的二进制文件,解压,设置环境变量。MySQL版本为5.1.38,my.cnf里的[mysqld]里的datadir参数为datadir=/data

1.[root@DB1 bin]#wget
2.[root@DB1 bin]#tar xzvf xtrabackup-0.9.tar.gz
3.[root@DB1 bin]#cd xtrabackup-0.9/bin/
4.[root@DB1 bin]#export PATH=$PATH:/root/xtrabackup-0.9/bin
备份所有数据库,备份目录为/tmp/backup/,innobackupex自动在这个目录下生成 年-月-日_时-分-秒 这类目录,目录下即为备份的文件。

01.[root@DB1 bin]# ./innobackupex-1.5.1  /tmp/backup/    --defaults-file=/etc/my.cnf
02.InnoDB Backup Utility v1.5.1-xtrabackup; Copyright 2003, 2009 Innobase Oy.
03.All Rights Reserved.
04.
 
05....省略N行...
06.
 
07.innobackupex: Backup created in directory '/tmp/backup/2009-10-09_04-35-13'
08.innobackupex: MySQL binlog position: filename 'mysql-bin.000001', position 722
09.091009 04:35:45  innobackupex: innobackup completed OK!
关闭MySQL,并删除MySQL datadir目录下的所有文件。

1.[root@DB1 bin]# service mysqld stop
2.Shutting down MySQL...                                     [确定]
3.[root@DB1 bin]# rm -rf /data/*
生成ib_logfile文件

1.[root@DB1 bin]# ./innobackupex-1.5.1 --apply-log /tmp/backup/2009-10-09_04-35-13/   --defaults-file=/etc/my.cnf
2.
 
3....省略N行...
4.
 
5.091009 04:37:11  innobackupex: innobackup completed OK!
这个命令后,/tmp/backup/2009-10-09_04-35-13/目录生成了以下两个文件。
ib_logfile0 ib_logfile1

接下来就是将整个文件夹里的内容复制到mysql datadir目录,并重新设置权限即可恢复。

01.[root@DB1 bin]# ./innobackupex-1.5.1 --copy-back /tmp/backup/2009-10-09_04-35-13/  --defaults-file=/etc/my.cnf
02.InnoDB Backup Utility v1.5.1-xtrabackup; Copyright 2003, 2009 Innobase Oy.
03.All Rights Reserved.
04.
 
05....省略N行...
06.
 
07.091009 04:40:07  innobackupex: innobackup completed OK!
08.[root@DB1 bin]# chown mysql:mysql /data/ -R
09.[root@DB1 bin]# service mysqld start
10.Starting MySQL.                                            [确定]

linux

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:RHEL5.3 安装Oracle 11gNächster Artikel:在RedHat 5上安装Oracle 10g