ibbackup vs mysqldump对比测试 - 20080718
Upcoming SlideShare
Loading in...5
×
 

ibbackup vs mysqldump对比测试 - 20080718

on

  • 1,072 views

ibbackup vs mysqldump对比测试

ibbackup vs mysqldump对比测试

Statistics

Views

Total Views
1,072
Views on SlideShare
1,072
Embed Views
0

Actions

Likes
0
Downloads
0
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft Word

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

ibbackup vs mysqldump对比测试 - 20080718 ibbackup vs mysqldump对比测试 - 20080718 Document Transcript

  • 前言:随着数据量的增加,备份问题会越来越突出,尤其是当前没有免费热备 工具的情形下。本文针对 InnoDB 的备份需求,采用商业的 ibbackup 以及免费 的 mysqldump 2 种工具进行对比,让大家有个大致的了解。 1. 准备 ibbackup 是 InnoDB 提供的收费工具,它支持在线热备 InnoDB 数据,主要有 以下特性: • * Online backup of InnoDB tables — the backup takes place entirely online, without preventing queries or updates. • * Online backup of MyISAM tables — during the backup of InnoDB tables, read and write access is permitted to MyISAM tables. While the MyISAM tables are being copied, updates (but not reads) to the MyISAM tables are precluded. • * Compressed backups — the backup of InnoDB files can be compressed at various levels, saving as much as 70% or more of the storage required. • * Partial backups — you can selectively backup all or only some of your InnoDB tables. • * High performance — backup time is comparable to file copy, applying logs for recovery is even faster.
  • • * Unlimited database size — no practical limit to database size or number of tables. • * Broad platform support — runs on Linux, Windows and leading Unix platforms. 在 innodb 官网 申请了个试用版测试下,发现效果还是不错的,不过在我们自 己的独特应用环境下,ibbackup 的优势并没有多少。具体的测试结果就不发上 来了,有兴趣的同学自己测试看看吧。 ibbackup 只需要识别简单的几个 InnoDB 相关参数即可。它在备份时需要用到 2 个配置文件,一个是指定在线运行的信息,一个是备份相关信息。例如: online-my.cnf 告诉 ibbackup 当前正在运行的 mysql 数据文件所在目录 [mysqld] datadir = /home/mysql innodb_data_file_path = ibdata1:512M:autoextend innodb_data_home_dir = /home/mysql innodb_log_file_size = 256M innodb_log_files_in_group = 3 innodb_log_group_home_dir = /home/mysql backup-my.cnf 告诉 ibbackup 备份文件存储的目录
  • [mysqld] datadir = /home/hotbackup innodb_data_file_path = ibdata1:512M:autoextend innodb_data_home_dir = /home/hotbackup innodb_log_file_size = 256M innodb_log_files_in_group = 3 innodb_log_group_home_dir = /home/hotbackup 运行 ibbackup --help,就能看到以下几个主要选项: [yejr@imysql.cn]# ibbackup --help Usage: ibbackup [--sleep ms] [--suspend-at-end] [--compress [level]] [--include regexp] my.cnf backup-my.cnf or ibbackup --apply-log [--use-memory mb] [--uncompress] backup-my.cnf or ibbackup --restore [--use-memory mb] [--uncompress] backup-my.cnf
  • 我一般只需要用到 --compress 以及 --uncompress,告诉 ibbackup 压缩/解压 缩的级别。 2. 备份 执行以下命令: [yejr@imysql.cn]# ibbackup --compress 5 online-my.cnf backup-my.cnf InnoDB Hot Backup version 3.0.0; Copyright 2002-2005 Innobase Oy License A13002 is granted to imysql Inc. (imysql@imysql.cn) (--apply-log works in any computer regardless of the hostname) Licensed for use in a computer whose hostname is 'yejr.imysql.cn' Expires 2008-9-1 (year-month-day) at 00:00 See http://www.innodb.com for further information Type ibbackup --license for detailed license terms, --help for help Contents of online-my.cnf: innodb_data_home_dir got value /home/mysql innodb_data_file_path got value ibdata1:512M:autoextend datadir got value /home/mysql innodb_log_group_home_dir got value /home/mysql innodb_log_files_in_group got value 3 innodb_log_file_size got value 268435456 Contents of backup-my.cnf:
  • innodb_data_home_dir got value /home/hotbackup innodb_data_file_path got value ibdata1:512M:autoextend datadir got value /home/hotbackup innodb_log_group_home_dir got value /home/hotbackup innodb_log_files_in_group got value 3 innodb_log_file_size got value 268435456 ibbackup: Found checkpoint at lsn 8 804380391 ibbackup: Starting log scan from lsn 8 804380160 080716 19:50:47 ibbackup: Copying log... 080716 19:50:47 ibbackup: Log copied, lsn 8 804380391 ibbackup: We wait 1 second before starting copying the data files... 080716 19:50:48 ibbackup: Copying /home/mysql/ibdata1 ibbackup: Progress in MB: 100 200 300 400 500 600 700 800 900 1000 080716 19:51:21 ibbackup: Copying /home/mysql/test/sbtest.ibd ibbackup: Progress in MB: 100 200 300 400 080716 19:51:34 ibbackup: Copying /home/mysql/test/geom.ibd 080716 19:51:34 ibbackup: Copying /home/mysql/test/t.ibd 080716 19:51:34 ibbackup: Copying /home/mysql/test/sbtest1.ibd ibbackup: Progress in MB: 100 200 300 400 080716 19:51:50 ibbackup: Copying /home/mysql/yejr/yejr.ibd ibbackup: Progress in MB: 100 200 300 400 500 600 700 800 900 1000 1100 1200 1300 1400 1500 1600 1700 1800 1900 2000 2100 2200 2300
  • ............ ibbackup: A copied database page was modified at 8 804394835 ibbackup: Scanned log up to lsn 8 804394835 ibbackup: Was able to parse the log up to lsn 8 804394835 ibbackup: Maximum page number for a log record 209 080716 19:53:03 ibbackup: Full backup completed! 就会在 /home/hotbackup 下产生相应备份文件,例如 [yejr@imysql.cn]# ls -l hotbackup/ total 34368 -rw-r----- 1 root root 1024 Jul 17 17:40 ibbackup_logfile -rw-r----- 1 root root 35128069 Jul 17 17:38 ibdata1.ibz drwxr-x--- 2 root root 4096 Jul 17 17:39 yejr drwxr-x--- 2 root root 4096 Jul 17 17:38 test 在备份过程中,还可以持续的提交事务,例如增、删、改数据等,ibbackup 会以 最后一次提交的事务为准,取得最新备份。 压缩级别视各自的实际情况而定了。一般需要通过测试,得到一个中间折中值。
  • 3. 还原 [yejr@imysql.cn]# ibbackup --uncompress 5 --apply-log backup-my.cnf InnoDB Hot Backup version 3.0.0; Copyright 2002-2005 Innobase Oy License A13002 is granted to imysql Inc. (imysql@gmail.com) (--apply-log works in any computer regardless of the hostname) Licensed for use in a computer whose hostname is 's01_tc_10.11.54.189_CNC' Expires 2008-9-1 (year-month-day) at 00:00 See http://www.innodb.com for further information Type ibbackup --license for detailed license terms, --help for help Contents of backup-my.cnf: innodb_data_home_dir got value /home/hotbackup innodb_data_file_path got value ibdata1:512M:autoextend datadir got value /home/hotbackup innodb_log_group_home_dir got value /home/hotbackup innodb_log_files_in_group got value 3 innodb_log_file_size got value 268435456 ibbackup: Uncompressing data file '/home/hotbackup/ibdata1.ibz' ibbackup: Progress in MB: 100 200 300 400 500 600 700 800 900 1000 ibbackup: Uncompressing data file '/home/hotbackup/test/sbtest.ibz' ibbackup: Progress in MB: 100 200 300 400
  • ibbackup: Uncompressing data file '/home/hotbackup/test/geom.ibz' ibbackup: Uncompressing data file '/home/hotbackup/test/t.ibz' ibbackup: Uncompressing data file '/home/hotbackup/test/sbtest1.ibz' ibbackup: Progress in MB: 100 200 300 400 ........ ibbackup: Uncompressing data file '/home/hotbackup/yejr/yejr.ibz' ibbackup: Progress in MB: 100 200 300 400 500 600 700 800 900 1000 1100 1200 1300 1400 1500 1600 1700 1800 1900 2000 2100 2200 2300 ........ 080717 17:49:43 ibbackup: ibbackup_logfile's creation parameters: ibbackup: start lsn 8 872965632, end lsn 8 872966026, ibbackup: start checkpoint 8 872966026 InnoDB: Doing recovery: scanned up to log sequence number 8 872966026 InnoDB: Starting an apply batch of log records to the database... InnoDB: Progress in percents: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 Setting log file size to 0 268435456 InnoDB: Progress in MB: 100 200 Setting log file size to 0 268435456 InnoDB: Progress in MB: 100 200
  • Setting log file size to 0 268435456 InnoDB: Progress in MB: 100 200 ibbackup: We were able to parse ibbackup_logfile up to ibbackup: lsn 8 872966026 ibbackup: The first data file is '/home/hotbackup/ibdata1' ibbackup: and the new created log files are at '/home/hotbackup/' 080717 17:50:10 ibbackup: Full backup prepared for recovery successfully! 然后把还原出来的数据文件 "冷" 拷贝到 mysql 的 datadir 下,启动 mysqld,即 可正常使用了。 从测试结果来看,ibbackup 备份和恢复是基于物理块级,把每个表空间文件做 一个干净的备份,并且支持备份同时有事务提交,以得到最新的数据备份。 因此 ibbackup 产生的备份文件如果不经压缩(不管是备份时压缩,还是事后压 缩),那么占用的空间会比较大。 mysqldump 可以用 single-transaction 来得到一致性备份,但是备份的数据是 发起操作的瞬间快照,之后提交的事务都不会在备份 中体现。mysqldump 可能会导致 log purge 停滞很长时间,使得 mysql 的响应 变得非常慢,这点 ibbackup 就可以避免。mysqldump 产生的备份文件相对 ibbackup 生成的小多了。 还原时,ibbackup 相比重新导入 sql 文件会快不少,在这方面,ibbackup 有非 常大的优势。
  • Setting log file size to 0 268435456 InnoDB: Progress in MB: 100 200 ibbackup: We were able to parse ibbackup_logfile up to ibbackup: lsn 8 872966026 ibbackup: The first data file is '/home/hotbackup/ibdata1' ibbackup: and the new created log files are at '/home/hotbackup/' 080717 17:50:10 ibbackup: Full backup prepared for recovery successfully! 然后把还原出来的数据文件 "冷" 拷贝到 mysql 的 datadir 下,启动 mysqld,即 可正常使用了。 从测试结果来看,ibbackup 备份和恢复是基于物理块级,把每个表空间文件做 一个干净的备份,并且支持备份同时有事务提交,以得到最新的数据备份。 因此 ibbackup 产生的备份文件如果不经压缩(不管是备份时压缩,还是事后压 缩),那么占用的空间会比较大。 mysqldump 可以用 single-transaction 来得到一致性备份,但是备份的数据是 发起操作的瞬间快照,之后提交的事务都不会在备份 中体现。mysqldump 可能会导致 log purge 停滞很长时间,使得 mysql 的响应 变得非常慢,这点 ibbackup 就可以避免。mysqldump 产生的备份文件相对 ibbackup 生成的小多了。 还原时,ibbackup 相比重新导入 sql 文件会快不少,在这方面,ibbackup 有非 常大的优势。