教你如何恢复使用MEB备份的MySQL数据库
恢复使用meb备份的mysql数据库,执行一个普通备份
[root@test bin]# ./mysqlbackup --defaults-file=/service/mysql5.5/my.cnf --socket=/data/mysql5.5/mysql.sock --user=root --backup-dir=/backup/5.5/normal --password backup mysql enterprise backup version 3.8.2 [2013/06/18] copyright (c) 2003, 2012,oracle and/or its affiliates. all rights reserved. mysqlbackup: info: starting with following command line ... ./mysqlbackup --defaults-file=/service/mysql5.5/my.cnf --socket=/data/mysql5.5/mysql.sock --user=root --backup-dir=/backup/5.5/normal --password backup enter password: mysqlbackup: info: mysql server version is '5.5.25-log'. mysqlbackup: info: got some server configuration information from running server. important: please check that mysqlbackup run completes successfully. at the end of a successful 'backup' run mysqlbackup prints "mysqlbackup completed ok!".
--------------------------------------------------------------------
server repository options:
--------------------------------------------------------------------
datadir = /data/mysql5.5/ innodb_data_home_dir = innodb_data_file_path = ibdata1:10m:autoextend innodb_log_group_home_dir = /data/mysql5.5/ innodb_log_files_in_group = 3 innodb_log_file_size = 536870912 innodb_page_size = null innodb_checksum_algorithm = innodb
--------------------------------------------------------------------
backup config options:
--------------------------------------------------------------------
datadir = /backup/5.5/normal/datadir innodb_data_home_dir = /backup/5.5/normal/datadir innodb_data_file_path = ibdata1:10m:autoextend innodb_log_group_home_dir = /backup/5.5/normal/datadir innodb_log_files_in_group = 3 innodb_log_file_size = 536870912 innodb_page_size = 16384 innodb_checksum_algorithm = innodb mysqlbackup: info: unique generated backup id for this is 13851351066141087 mysqlbackup: info: uses posix_fadvise() for performance optimization. mysqlbackup: info: creating 14 buffers each of size 16777216. 131122 23:45:08 mysqlbackup: info: full backup operation starts with following threads 1 read-threads 6 process-threads 1 write-threads 131122 23:45:08 mysqlbackup: info: system tablespace file format is antelope. 131122 23:45:08 mysqlbackup: info: starting to copy all innodb files... 131122 23:45:08 mysqlbackup: info: copying /data/mysql5.5/ibdata1 (antelope file format). 131122 23:45:08 mysqlbackup: info: found checkpoint at lsn 3406087628. 131122 23:45:08 mysqlbackup: info: starting log scan from lsn 3406087168. 131122 23:45:08 mysqlbackup: info: copying log... 131122 23:45:08 mysqlbackup: info: log copied, lsn 3406087628. 131122 23:45:08 mysqlbackup: info: copying /data/mysql5.5/common_schema/_global_qs_variables.ibd (antelope file format). 131122 23:45:08 mysqlbackup: info: copying /data/mysql5.5/common_schema/_global_script_report_data.ibd (antelope file format). 131122 23:45:08 mysqlbackup: info: copying /data/mysql5.5/common_schema/_global_split_column_names_table.ibd (antelope file format). 131122 23:45:08 mysqlbackup: info: copying /data/mysql5.5/common_schema/_global_sql_tokens.ibd (antelope file format). 131122 23:45:08 mysqlbackup: info: copying /data/mysql5.5/common_schema/_known_thread_states.ibd (antelope file format). 131122 23:45:08 mysqlbackup: info: copying /data/mysql5.5/common_schema/_named_scripts.ibd (antelope file format). 131122 23:45:08 mysqlbackup: info: copying /data/mysql5.5/common_schema/_script_statements.ibd (antelope file format). 131122 23:45:08 mysqlbackup: info: copying /data/mysql5.5/common_schema/_waits.ibd (antelope file format). 131122 23:45:08 mysqlbackup: info: copying /data/mysql5.5/common_schema/help_content.ibd (antelope file format). 131122 23:45:08 mysqlbackup: info: copying /data/mysql5.5/common_schema/metadata.ibd (antelope file format). 131122 23:45:08 mysqlbackup: info: copying /data/mysql5.5/common_schema/numbers.ibd (antelope file format). 131122 23:45:08 mysqlbackup: info: copying /data/mysql5.5/zwc/t2.ibd (antelope file format). mysqlbackup: progress in mb: 200 400 131122 23:45:20 mysqlbackup: info: completing the copy of innodb files. 131122 23:45:21 mysqlbackup: info: preparing to lock tables: connected to mysqld server. 131122 23:45:21 mysqlbackup: info: starting to lock all the tables... 131122 23:45:21 mysqlbackup: info: all tables are locked and flushed to disk 131122 23:45:21 mysqlbackup: info: opening backup source directory '/data/mysql5.5/' 131122 23:45:21 mysqlbackup: info: starting to backup all non-innodb files in subdirectories of '/data/mysql5.5/' 131122 23:45:21 mysqlbackup: info: copying the database directory 'common_schema' 131122 23:45:21 mysqlbackup: info: copying the database directory 'mysql' 131122 23:45:21 mysqlbackup: info: copying the database directory 'performance_schema' 131122 23:45:21 mysqlbackup: info: copying the database directory 'test' 131122 23:45:21 mysqlbackup: info: copying the database directory 'zwc' mysqlbackup: progress in mb: 600 800 131122 23:45:33 mysqlbackup: info: completing the copy of all non-innodb files. 131122 23:45:35 mysqlbackup: info: a copied database page was modified at 3406087628. (this is the highest lsn found on page) scanned log up to lsn 3406090810. was able to parse the log up to lsn 3406090810. maximum page number for a log record 315 131122 23:45:35 mysqlbackup: info: all tables unlocked 131122 23:45:35 mysqlbackup: info: all mysql tables were locked for 13.758 seconds. 131122 23:45:35 mysqlbackup: info: full backup operation completed successfully. 131122 23:45:35 mysqlbackup: info: backup created in directory '/backup/5.5/normal' 131122 23:45:35 mysqlbackup: info: mysql binlog position: filename zwc-test.000024, position 16178 ------------------------------------------------------------- parameters summary ------------------------------------------------------------- start lsn : 3406087168 end lsn : 3406090810 ------------------------------------------------------------- mysqlbackup completed ok!
或者压缩备份
[root@test bin]# ./mysqlbackup --defaults-file=/service/mysql5.5/my.cnf --socket=/data/mysql5.5/mysql.sock --user=root --backup-dir=/backup/5.5/compress --compress --password backup mysql enterprise backup version 3.8.2 [2013/06/18] copyright (c) 2003, 2012, oracle and/or its affiliates. all rights reserved. mysqlbackup: info: starting with following command line ... ./mysqlbackup --defaults-file=/service/mysql5.5/my.cnf --socket=/data/mysql5.5/mysql.sock --user=root --backup-dir=/backup/5.5/compress --compress --password backup enter password: mysqlbackup: info: mysql server version is '5.5.25-log'. mysqlbackup: info: got some server configuration information from running server. important: please check that mysqlbackup run completes successfully. at the end of a successful 'backup' run mysqlbackup prints "mysqlbackup completed ok!".
--------------------------------------------------------------------
server repository options:
--------------------------------------------------------------------
datadir = /data/mysql5.5/ innodb_data_home_dir = innodb_data_file_path = ibdata1:10m:autoextend innodb_log_group_home_dir = /data/mysql5.5/ innodb_log_files_in_group = 3 innodb_log_file_size = 536870912 innodb_page_size = null innodb_checksum_algorithm = innodb
--------------------------------------------------------------------
backup config options:
--------------------------------------------------------------------
datadir = /backup/5.5/compress/datadir innodb_data_home_dir = /backup/5.5/compress/datadir innodb_data_file_path = ibdata1:10m:autoextend innodb_log_group_home_dir = /backup/5.5/compress/datadir innodb_log_files_in_group = 3 innodb_log_file_size = 536870912 innodb_page_size = 16384 innodb_checksum_algorithm = innodb mysqlbackup: info: unique generated backup id for this is 13851352214073555 mysqlbackup: info: uses posix_fadvise() for performance optimization. mysqlbackup: info: creating 18 buffers each of size 16794070. 131122 23:47:03 mysqlbackup: info: compress backup operation starts with following threads 1 read-threads 6 process-threads 1 write-threads 131122 23:47:03 mysqlbackup: info: system tablespace file format is antelope. 131122 23:47:03 mysqlbackup: info: starting to copy all innodb files... 131122 23:47:03 mysqlbackup: info: copying /data/mysql5.5/ibdata1 (antelope file format). 131122 23:47:03 mysqlbackup: info: found checkpoint at lsn 3406092146. 131122 23:47:03 mysqlbackup: info: starting log scan from lsn 3406091776. 131122 23:47:03 mysqlbackup: info: copying log... 131122 23:47:03 mysqlbackup: info: log copied, lsn 3406092146. 131122 23:47:03 mysqlbackup: info: copying /data/mysql5.5/common_schema/_global_qs_variables.ibd (antelope file format). 131122 23:47:03 mysqlbackup: info: copying /data/mysql5.5/common_schema/_global_script_report_data.ibd (antelope file format). 131122 23:47:03 mysqlbackup: info: copying /data/mysql5.5/common_schema/_global_split_column_names_table.ibd (antelope file format). 131122 23:47:03 mysqlbackup: info: copying /data/mysql5.5/common_schema/_global_sql_tokens.ibd (antelope file format). 131122 23:47:03 mysqlbackup: info: copying /data/mysql5.5/common_schema/_known_thread_states.ibd (antelope file format). 131122 23:47:03 mysqlbackup: info: copying /data/mysql5.5/common_schema/_named_scripts.ibd (antelope file format). 131122 23:47:03 mysqlbackup: info: copying /data/mysql5.5/common_schema/_script_statements.ibd (antelope file format). 131122 23:47:03 mysqlbackup: info: copying /data/mysql5.5/common_schema/_waits.ibd (antelope file format). 131122 23:47:03 mysqlbackup: info: copying /data/mysql5.5/common_schema/help_content.ibd (antelope file format). 131122 23:47:03 mysqlbackup: info: copying /data/mysql5.5/common_schema/metadata.ibd (antelope file format). 131122 23:47:03 mysqlbackup: info: copying /data/mysql5.5/common_schema/numbers.ibd (antelope file format). 131122 23:47:03 mysqlbackup: info: copying /data/mysql5.5/zwc/t2.ibd (antelope file format). mysqlbackup: progress in mb: 200 400 131122 23:47:11 mysqlbackup: info: completing the copy of innodb files. 131122 23:47:14 mysqlbackup: info: preparing to lock tables: connected to mysqld server. 131122 23:47:14 mysqlbackup: info: starting to lock all the tables... 131122 23:47:14 mysqlbackup: info: all tables are locked and flushed to disk 131122 23:47:14 mysqlbackup: info: opening backup source directory '/data/mysql5.5/' 131122 23:47:14 mysqlbackup: info: starting to backup all non-innodb files in subdirectories of '/data/mysql5.5/' 131122 23:47:14 mysqlbackup: info: copying the database directory 'common_schema' 131122 23:47:14 mysqlbackup: info: copying the database directory 'mysql' 131122 23:47:15 mysqlbackup: info: copying the database directory 'performance_schema' 131122 23:47:15 mysqlbackup: info: copying the database directory 'test' 131122 23:47:15 mysqlbackup: info: copying the database directory 'zwc' mysqlbackup: progress in mb: 600 800 131122 23:47:26 mysqlbackup: info: completing the copy of all non-innodb files. 131122 23:47:28 mysqlbackup: info: a copied database page was modified at 3406092146. (this is the highest lsn found on page) scanned log up to lsn 3406095314. was able to parse the log up to lsn 3406095314. maximum page number for a log record 319 131122 23:47:29 mysqlbackup: info: all tables unlocked 131122 23:47:29 mysqlbackup: info: all mysql tables were locked for 14.330 seconds. 131122 23:47:29 mysqlbackup: info: compressed 496 mb of data files to 200577 kbytes (compression 60.51%). 131122 23:47:29 mysqlbackup: info: compress backup operation completed successfully. 131122 23:47:29 mysqlbackup: info: backup created in directory '/backup/5.5/compress' 131122 23:47:29 mysqlbackup: info: mysql binlog position: filename zwc-test.000024, position 24831 ------------------------------------------------------------- parameters summary ------------------------------------------------------------- start lsn : 3406091776 end lsn : 3406095314 ------------------------------------------------------------- mysqlbackup completed ok!
停止mysql服务
[root@test mysql5.5]# /service/mysql5.5/bin/mysqladmin shutdown -uroot -p
删除数据目录里的文件
[root@test mysql5.5]# rm -rf common_schema/ mysql/ performance_schema/ test/ zwc/
从备份中还原
[root@test bin]# ./mysqlbackup --defaults-file=/service/mysql5.5/my.cnf --backup-dir=/backup/5.5/normal apply-log mysql enterprise backup version 3.8.2 [2013/06/18] copyright (c) 2003, 2012, oracle and/or its affiliates. all rights reserved. mysqlbackup: info: starting with following command line ... ./mysqlbackup --defaults-file=/service/mysql5.5/my.cnf --backup-dir=/backup/5.5/normal apply-log important: please check that mysqlbackup run completes successfully. at the end of a successful 'apply-log' run mysqlbackup prints "mysqlbackup completed ok!".
--------------------------------------------------------------------
backup config options:
--------------------------------------------------------------------
datadir = /backup/5.5/normal/datadir innodb_data_home_dir = /backup/5.5/normal/datadir innodb_data_file_path = ibdata1:10m:autoextend innodb_log_group_home_dir = /backup/5.5/normal/datadir innodb_log_files_in_group = 3 innodb_log_file_size = 536870912 innodb_page_size = 16384 innodb_checksum_algorithm = innodb mysqlbackup: info: uses posix_fadvise() for performance optimization. mysqlbackup: info: creating 14 buffers each of size 65536. 131122 23:59:39 mysqlbackup: info: apply-log operation starts with following threads 1 read-threads 1 process-threads 131122 23:59:39 mysqlbackup: info: ibbackup_logfile's creation parameters: start lsn 3406087168, end lsn 3406090810, start checkpoint 3406087628. innodb: doing recovery: scanned up to log sequence number 3406090810 mysqlbackup: info: innodb: starting an apply batch of log records to the database... innodb: progress in percent: 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 536870912 innodb: progress in mb: 100 200 300 400 500 setting log file size to 536870912 innodb: progress in mb: 100 200 300 400 500 setting log file size to 536870912 innodb: progress in mb: 100 200 300 400 500 131123 00:00:01 mysqlbackup: info: we were able to parse ibbackup_logfile up to lsn 3406090810. mysqlbackup: info: last mysql binlog file position 0 16178, file name ./zwc-test.000024 131123 00:00:01 mysqlbackup: info: the first data file is '/backup/5.5/normal/datadir/ibdata1' and the new created log files are at '/backup/5.5/normal/datadir' 131123 00:00:01 mysqlbackup: info: apply-log operation completed successfully. 131123 00:00:01 mysqlbackup: info: full backup prepared for recovery successfully. mysqlbackup completed ok![root@test bin]# ./mysqlbackup --defaults-file=/service/mysql5.5/my.cnf --backup-dir=/backup/5.5/normal copy-back mysql enterprise backup version 3.8.2 [2013/06/18] copyright (c) 2003, 2012, oracle and/or its affiliates. all rights reserved. mysqlbackup: info: starting with following command line ... ./mysqlbackup --defaults-file=/service/mysql5.5/my.cnf --backup-dir=/backup/5.5/normal copy-back important: please check that mysqlbackup run completes successfully. at the end of a successful 'copy-back' run mysqlbackup prints "mysqlbackup completed ok!".
--------------------------------------------------------------------
server repository options:
--------------------------------------------------------------------
datadir = /data/mysql5.5 innodb_data_home_dir = /data/mysql5.5 innodb_data_file_path = ibdata1:10m:autoextend innodb_log_group_home_dir = /data/mysql5.5 innodb_log_files_in_group = 3 innodb_log_file_size = 512m innodb_page_size = null innodb_checksum_algorithm = innodb
--------------------------------------------------------------------
backup config options:
--------------------------------------------------------------------
datadir = /backup/5.5/normal/datadir innodb_data_home_dir = /backup/5.5/normal/datadir innodb_data_file_path = ibdata1:10m:autoextend innodb_log_group_home_dir = /backup/5.5/normal/datadir innodb_log_files_in_group = 3 innodb_log_file_size = 536870912 innodb_page_size = 16384 innodb_checksum_algorithm = innodb mysqlbackup: info: uses posix_fadvise() for performance optimization. mysqlbackup: info: creating 14 buffers each of size 16777216. 131123 00:00:44 mysqlbackup: info: copy-back operation starts with following threads 1 read-threads 1 write-threads 131123 00:00:45 mysqlbackup: info: copying /backup/5.5/normal/datadir/ibdata1. 131123 00:00:45 mysqlbackup: info: copying /backup/5.5/normal/datadir/common_schema/_global_qs_variables.ibd. 131123 00:00:45 mysqlbackup: info: copying /backup/5.5/normal/datadir/common_schema/_global_script_report_data.ibd. 131123 00:00:45 mysqlbackup: info: copying /backup/5.5/normal/datadir/common_schema/_global_split_column_names_table.ibd. 131123 00:00:45 mysqlbackup: info: copying /backup/5.5/normal/datadir/common_schema/_global_sql_tokens.ibd. 131123 00:00:45 mysqlbackup: info: copying /backup/5.5/normal/datadir/common_schema/_known_thread_states.ibd. 131123 00:00:45 mysqlbackup: info: copying /backup/5.5/normal/datadir/common_schema/_named_scripts.ibd. 131123 00:00:45 mysqlbackup: info: copying /backup/5.5/normal/datadir/common_schema/_script_statements.ibd. 131123 00:00:45 mysqlbackup: info: copying /backup/5.5/normal/datadir/common_schema/_waits.ibd. 131123 00:00:45 mysqlbackup: info: copying /backup/5.5/normal/datadir/common_schema/help_content.ibd. 131123 00:00:45 mysqlbackup: info: copying /backup/5.5/normal/datadir/common_schema/metadata.ibd. 131123 00:00:45 mysqlbackup: info: copying /backup/5.5/normal/datadir/common_schema/numbers.ibd. 131123 00:00:45 mysqlbackup: info: copying /backup/5.5/normal/datadir/zwc/t2.ibd. mysqlbackup: progress in mb: 200 400 131123 00:00:54 mysqlbackup: info: copying the database directory 'common_schema' 131123 00:00:55 mysqlbackup: info: copying the database directory 'mysql' 131123 00:00:55 mysqlbackup: info: copying the database directory 'performance_schema' 131123 00:00:55 mysqlbackup: info: copying the database directory 'test' 131123 00:00:55 mysqlbackup: info: copying the database directory 'zwc' mysqlbackup: progress in mb: 600 800 131123 00:01:06 mysqlbackup: info: completing the copy of all non-innodb files. 131123 00:01:06 mysqlbackup: info: copying the log file 'ib_logfile0' mysqlbackup: progress in mb: 1000 1200 1400 131123 00:01:16 mysqlbackup: info: copying the log file 'ib_logfile1' mysqlbackup: progress in mb: 1600 1800 131123 00:01:27 mysqlbackup: info: copying the log file 'ib_logfile2' mysqlbackup: progress in mb: 2000 2200 2400 131123 00:01:38 mysqlbackup: info: copy-back operation completed successfully. 131123 00:01:38 mysqlbackup: info: finished copying backup files to '/data/mysql5.5' mysqlbackup completed ok!
设置权限,启动mysql服务
[root@test mysql5.5]# chown -r mysql.mysql * [root@test mysql5.5]# /service/mysql5.5/bin/mysqld_safe --defaults-file=/service/mysql5.5/my.cnf --basedir=/service/mysql5.5 --datadir=/data/mysql5.5 --user=mysql & [1] 6525 [root@test mysql5.5]# 131123 00:04:00 mysqld_safe logging to '/data/mysql5.5/test.err'. 131123 00:04:00 mysqld_safe starting mysqld daemon with databases from /data/mysql5.5[root@test mysql5.5]# cat test.err 131123 00:04:00 mysqld_safe starting mysqld daemon with databases from /data/mysql5.5 131123 0:04:00 innodb: the innodb memory heap is disabled 131123 0:04:00 innodb: mutexes and rw_locks use gcc atomic builtins 131123 0:04:00 innodb: compressed tables use zlib 1.2.3 131123 0:04:00 innodb: initializing buffer pool, size = 2.4g 131123 0:04:00 innodb: completed initialization of buffer pool 131123 0:04:00 innodb: highest supported file format is barracuda. innodb: log scan progressed past the checkpoint lsn 3406091276 131123 0:04:00 innodb: database was not shut down normally! innodb: starting crash recovery. innodb: reading tablespace information from the .ibd files... innodb: restoring possible half-written data pages from the doublewrite innodb: buffer... innodb: doing recovery: scanned up to log sequence number 3406091710 131123 0:04:01 innodb: starting an apply batch of log records to the database... innodb: progress in percents: 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 innodb: apply batch completed innodb: last mysql binlog file position 0 16178, file name ./zwc-test.000024 131123 0:04:01 innodb: waiting for the background threads to start 131123 0:04:02 innodb: 1.1.8 started; log sequence number 3406091710 131123 0:04:02 [note] recovering after a crash using zwc-test 131123 0:04:02 [note] starting crash recovery... 131123 0:04:02 [note] crash recovery finished. 131123 0:04:02 [note] server hostname (bind-address): '0.0.0.0'; port: 30306 131123 0:04:02 [note] - '0.0.0.0' resolves to '0.0.0.0'; 131123 0:04:02 [note] server socket created on ip: '0.0.0.0'. 131123 0:04:02 [warning] 'user' entry 'root@test' ignored in --skip-name-resolve mode. 131123 0:04:02 [warning] 'user' entry '@test' ignored in --skip-name-resolve mode. 131123 0:04:02 [warning] 'proxies_priv' entry '@ root@test' ignored in --skip-name-resolve mode. 131123 0:04:02 [note] event scheduler: loaded 0 events 131123 0:04:02 [note] /service/mysql5.5/bin/mysqld: ready for connections. version: '5.5.25-log' socket: '/data/mysql5.5/mysql.sock' port: 30306 zwc 131123 0:04:02 [note] event scheduler: scheduler thread started with id 1
数据库已经恢复
[root@test mysql5.5]# /service/mysql5.5/bin/mysql -uroot -p -d zwc enter password: welcome to the mysql monitor. commands end with ; or \g. your mysql connection id is 6 server version: 5.5.25-log zwc copyright (c) 2000, 2011, oracle and/or its affiliates. all rights reserved. oracle is a registered trademark of oracle corporation and/or its affiliates. other names may be trademarks of their respective owners. type 'help;' or '\h' for help. type '\c' to clear the current input statement. root@linuxidc12:05:07>select count(*),now() from t1; +----------+---------------------+ | count(*) | now() | +----------+---------------------+ | 10000000 | 2013-11-23 00:05:17 | +----------+---------------------+ 1 row in set (0.04 sec) root@linuxidc12:05:17>select count(*),now() from t2; +----------+---------------------+ | count(*) | now() | +----------+---------------------+ | 10000000 | 2013-11-23 00:05:19 | +----------+---------------------+ 1 row in set (2.91 sec)