下载 Linux binary , 这个还可用.
如果不想麻烦, 可直接将解压后的包里的 bin 下这两个文件全部扔到 /usr/bin 目录下.
[text]
[root@localhost bin]# ls -al
total 34108
-rwxr-xr-x 1 root root 85630 Dec 9 23:15 innobackupex-1.5.1
-rwxr-xr-x 1 root root 6316740 Dec 9 23:15 xtrabackup_51
......
[/text]
或者将其目录加入到环境变量 $PATH 中, 假设解压后的包放在 /var/tmp/mysql 目录下
[bash]
[root@localhost bin]PATH="$PATH:/var/tmp/mysql/xtrabackup-1.5/bin"
[root@localhost bin]export $PATH
[/bash]
MySQL bin 同样也需要加入$PATH 中
innobackupex-1.5.1 [--sleep=MS] [--compress[=LEVEL]] [--include=REGEXP] [--user=NAME]
[--password=WORD] [--port=PORT] [--socket=SOCKET] [--no-timestamp]
[--ibbackup=IBBACKUP-BINARY] [--slave-info] [--stream=tar]
[--scpopt=OPTIONS-FOR-SCP]
[--defaults-file=MY.CNF]
[--databases=LIST] [--remote-host=HOSTNAME] [--no-lock] BACKUP-ROOT-DIR
innobackupex-1.5.1 --apply-log [--use-memory=MB] [--uncompress] [--defaults-file=MY.CNF]
[--export] [--redo-only] [--ibbackup=IBBACKUP-BINARY] BACKUP-DIR
innobackupex-1.5.1 --copy-back [--defaults-file=MY.CNF] BACKUP-DIR--defaults-file=[MY.CNF]指定 MySQL 的配置文件--apply-log为恢复做准备--redo-only--apply-log组, 强制备份日志时只 redo ,跳过 rollback. 这在做增量备份时非常必要--copy-back将数据和日志从备份目录恢复到原始目录--remote-host在指定该参数的情况下, 备份的文件将通过 SSH 连接创建于指定的主机上--stream=[tar]备份文件输出格式, tar 时使用 tar4ibd , 该文件可在 XtarBackup binary 文件中获得--tmpdir=DIRECTORY当有指定--remote-hostor--stream时, 事务日志临时存储的目录, 默认采用 MySQL 配置文件中所指定的临时目录tmpdir--use-momory=MB这个用于 ibbackup 子处理 , 即恢复时可用上 MB 的内存--parallel=NUMBER-OF-THREADS这个用于 xtrabackup 子处理, 即备份时可并行运行的传输数据的进程--sleep=MS用于 ibbackup, 指在每 copy 1MB 的数据后sleep 的时间(unit:MS). 可缓和在运行 ibbackup 所导致的磁盘 I/O 问题.--compress=[LEVEL]用于ibbackup, 至在备份数据时压缩的级别. 0-9include=REGEXP只备份匹配的表的数据--databases=LIST指定备份的库, 格式如"db_name.[table_name] db_name2[table_name] ....". 没有指定时, MyISAM 和 InnoDB 的表都会备份
备份
[bash]
[root@localhost ~]# innobackupex-1.5.1 [--defaults-file=/etc/my.cnf] [--host=127.0.0.1] [--user=root] [--password=password] [--port=3306]
/tmp/backups/ 2>/tmp/backups/backup.log
[/bash]
2>/tmp/backups/backup.log, 是将备份过程中的输出信息重定向到 backup.log备份后的文件
xtrabackup_binlog_info存放binlog的信息. (binlog需要另外拷贝备份, 如果需要binlog的话)xtrabackup_checkpoints存放备份的起始位置和结束位置
恢复
停掉数据库, 然后删除数据库目录下的所有数据库文件.
[bash]
[root@localhost ~]# cd /usr/local/mysql/var/
[root@localhost var]# rm -rf *
[/bash]
开始恢复
[bash]
[root@localhost ~]# innobackupex-1.5.1 --user=root --apply-log /tmp/backups/2011-03-15_11-16-37 #应用日志
[root@localhost ~]# innobackupex-1.5.1 --user=root --copy-back /tmp/backups/2011-03-15_11-16-37
[/bash]
数据恢复后, 修改其属主
[bash]
[root@localhost mysql]# chown -R mysql:mysql var/
[/bash]
启动 MySQL 服务
[bash]
[root@localhost var]# mysqld_safe &
[/bash]
备份时压缩成 .tar
[bash]
[root@localhost ~]# innobackupex-1.5.1 [--defaults-file=/etc/my.cnf] [--host=127.0.0.1] [--user=root] [--password=password] [--port=3306] --stream=tar /tmp/backups/tar > /tmp/backups/tar.tar
[/bash]
解压
[bash]
[root@localhost var]# cd /tmp/backups/tar
[root@localhost tar]# tar ixvf tar.tar #i 必须
[/bash]
剩下的恢复操作同上.
备份时压缩成 .tar.gz
[bash]
[root@localhost ~]# innobackupex-1.5.1 [--defaults-file=/etc/my.cnf] [--host=127.0.0.1] [--user=root] [--password=password] [--port=3306] --stream=tar /tmp/backups/tar | gzip > /tmp/backups/tar.tar.gz
[/bash]
解压
[bash]
[root@localhost var]# cd /tmp/backups/tar
[root@localhost tar]# tar izxvf tar.tar.gz #i 必须
[/bash]
剩下的恢复操作同上.
--slave-info 参数
[bash]
[root@localhost ~]innobackupex-1.5.1 [--defaults-file=/etc/my.cnf] [--host=127.0.0.1] [--user=root] [--password=password] [--port=3306] --slave-info /tmp/backup/
[/bash]
备份从库, 加上
--slave-info 备份目录下会多生成一个 xtrabackup_slave_info 文件, 这里会保存主日志文件以及偏移, 文件内容类似于:[text]
CHANGE MASTER TO MASTER_LOG_FILE='', MASTER_LOG_POS=0
[/text]
--databases 参数
这个参数用于指定备份的库或者表, 格式如
--databases="dbname.[table_name] dbname2.[table_name2] ..."没指定该参数时, 所有库都会备份(包括 MyISAM 存储引擎). 另外, 若指定的库是 MyISAM 存储引擎, 同样也会备份.
注意点
- xtarbackup bin 下文件所处的目录要在 $PATH 中
- MySQL 配置文件中一定有指定 datadir目录
- 如果备份时有指定
--stream=tar, 则tar4ibd 文件所处目录一定要在 $PATH 中(因为使用的是 tar4ibd 去压缩, 在 XtraBackup 的 binary 包中可获得该文件)
没有评论:
发表评论