MySQL的企业备份(MEB)

一、安装

https://edelivery.oracle.com

[[email protected] meb]# ll

total 2936

-rw-r--r-- 1 root root 2998307 Jan 30 16:02 V59673-01.zip

[[email protected] meb]# unzip V59673-01.zip

Archive:  V59673-01.zip

extracting: meb-3.11.1-rhel5.i386.rpm

extracting: README.txt

[[email protected] meb]# rpm -ivh meb-3.11.1-rhel5.i386.rpm

[[email protected] meb]# find / -name mysqlbackup

/opt/mysql/meb-3.11/bin/mysqlbackup

[[email protected] meb]# cp /opt/mysql/meb-3.11/bin/mysqlbackup /usr/bin/

二、创建备份账号并赋予特权

为了使特权用户能够利用MEB进行备份,就需要提高访问权限,这些特权包括:

mysql> CREATE USER [email protected] IDENTIFIED BY ‘123456‘;

Query OK, 0 rows affected (0.00 sec)

mysql> GRANT RELOAD,REPLICATION CLIENT,SUPER,CREATE TEMPORARY TABLES ON *.* TO ‘dbbackup‘@‘localhost‘;

Query OK, 0 rows affected (0.00 sec)

mysql> GRANT CREATE,INSERT,DROP ON mysql.backup_progress TO ‘dbbackup‘@‘localhost‘;

Query OK, 0 rows affected (0.01 sec)

mysql> GRANT CREATE,INSERT,DROP ON mysql.backup_history TO ‘dbbackup‘@‘localhost‘;

Query OK, 0 rows affected (0.00 sec)

三、备份

[[email protected] backup]# time mysqlbackup --user=dbbackup --password=123456 --backup-dir=/home/backup/${HOSTNAME}_`date +"%Y%m%d_%H:%M:%S"` backup-and-apply-log

MySQL Enterprise Backup version 3.11.1 Linux-2.6.18-92.1.10.el5-i686 [2014/11/04]

Copyright (c) 2003, 2014, Oracle and/or its affiliates. All Rights Reserved.

mysqlbackup: INFO: Starting with following command line ...

mysqlbackup --user=dbbackup --password=xxxxxx

--backup-dir=/home/backup/gflinux_20150130_16:37:30

backup-and-apply-log

mysqlbackup: INFO:

mysqlbackup: INFO: MySQL server version is ‘5.6.21‘.

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-and-apply-log‘ run mysqlbackup

prints "mysqlbackup completed OK!".

150130 16:37:30 mysqlbackup: INFO: MEB logfile created at /home/backup/gflinux_20150130_16:37:30/meta/MEB_2015-01-30.16-37-30_backup_apply_log.log

--------------------------------------------------------------------

Server Repository Options:

--------------------------------------------------------------------

datadir = /opt/mysql/data/

innodb_data_home_dir =

innodb_data_file_path = ibdata1:12M:autoextend

innodb_log_group_home_dir = /opt/mysql/data/

innodb_log_files_in_group = 2

innodb_log_file_size = 50331648

innodb_page_size = 16384

innodb_checksum_algorithm = innodb

innodb_undo_directory = /opt/mysql/data/

innodb_undo_tablespaces = 0

innodb_undo_logs = 128

--------------------------------------------------------------------

Backup Config Options:

--------------------------------------------------------------------

datadir = /home/backup/gflinux_20150130_16:37:30/datadir

innodb_data_home_dir = /home/backup/gflinux_20150130_16:37:30/datadir

innodb_data_file_path = ibdata1:12M:autoextend

innodb_log_group_home_dir = /home/backup/gflinux_20150130_16:37:30/datadir

innodb_log_files_in_group = 2

innodb_log_file_size = 50331648

innodb_page_size = 16384

innodb_checksum_algorithm = innodb

innodb_undo_directory = /home/backup/gflinux_20150130_16:37:30/datadir

innodb_undo_tablespaces = 0

innodb_undo_logs = 128

mysqlbackup: INFO: Unique generated backup id for this is 14226070505710696

mysqlbackup: INFO: Creating 14 buffers each of size 16777216.

150130 16:37:32 mysqlbackup: INFO: Full Backup operation starts with following threads

1 read-threads    6 process-threads    1 write-threads

150130 16:37:32 mysqlbackup: INFO: System tablespace file format is Antelope.

150130 16:37:32 mysqlbackup: INFO: Starting to copy all innodb files...

mysqlbackup: INFO: Could not find binlog index file. binlogs will not be copied for this backup.

Point-In-Time-Recovery will not be possible.

If this is online backup then server may not have started with --log-bin.

You may specify its location with --log-bin-index option.

150130 16:37:32 mysqlbackup: INFO: Found checkpoint at lsn 1633585.

150130 16:37:32 mysqlbackup: INFO: Starting log scan from lsn 1633280.

150130 16:37:32 mysqlbackup: INFO: Copying log...

150130 16:37:32 mysqlbackup: INFO: Log copied, lsn 1633585.

150130 16:37:32 mysqlbackup: INFO: Copying /opt/mysql/data/ibdata1 (Antelope file format).

150130 16:37:32 mysqlbackup: INFO: Copying /opt/mysql/data/mysql/innodb_index_stats.ibd (Antelope file format).

150130 16:37:32 mysqlbackup: INFO: Copying /opt/mysql/data/mysql/innodb_table_stats.ibd (Antelope file format).

150130 16:37:32 mysqlbackup: INFO: Copying /opt/mysql/data/mysql/slave_master_info.ibd (Antelope file format).

150130 16:37:32 mysqlbackup: INFO: Copying /opt/mysql/data/mysql/slave_relay_log_info.ibd (Antelope file format).

150130 16:37:32 mysqlbackup: INFO: Copying /opt/mysql/data/mysql/slave_worker_info.ibd (Antelope file format).

150130 16:37:32 mysqlbackup: INFO: Copying /opt/mysql/data/test/t.ibd (Antelope file format).

150130 16:37:32 mysqlbackup: INFO: Completing the copy of innodb files.

150130 16:37:33 mysqlbackup: INFO: Preparing to lock tables: Connected to mysqld server.

150130 16:37:33 mysqlbackup: INFO: Starting to lock all the tables...

150130 16:37:33 mysqlbackup: INFO: All tables are locked and flushed to disk

150130 16:37:33 mysqlbackup: INFO: Opening backup source directory ‘/opt/mysql/data/‘

150130 16:37:33 mysqlbackup: INFO: Starting to backup all non-innodb files in

subdirectories of ‘/opt/mysql/data/‘

150130 16:37:33 mysqlbackup: INFO: Copying the database directory ‘mysql‘

150130 16:37:34 mysqlbackup: INFO: Copying the database directory ‘performance_schema‘

150130 16:37:34 mysqlbackup: INFO: Copying the database directory ‘test‘

150130 16:37:34 mysqlbackup: INFO: Completing the copy of all non-innodb files.

150130 16:37:35 mysqlbackup: INFO: A copied database page was modified at 1633585.

(This is the highest lsn found on page)

Scanned log up to lsn 1633585.

Was able to parse the log up to lsn 1633585.

Maximum page number for a log record 0

150130 16:37:35 mysqlbackup: INFO: All tables unlocked

150130 16:37:35 mysqlbackup: INFO: All MySQL tables were locked for 1.748 seconds.

150130 16:37:35 mysqlbackup: INFO: Reading all global variables from the server.

150130 16:37:35 mysqlbackup: INFO: Completed reading of all global variables from the server.

150130 16:37:35 mysqlbackup: INFO: Creating server config files server-my.cnf and server-all.cnf in /home/backup/gflinux_20150130_16:37:30

150130 16:37:35 mysqlbackup: INFO: Full Backup operation completed successfully.

150130 16:37:35 mysqlbackup: INFO: Backup created in directory ‘/home/backup/gflinux_20150130_16:37:30‘

-------------------------------------------------------------

Parameters Summary

-------------------------------------------------------------

Start LSN                  : 1633280

End LSN                    : 1633585

-------------------------------------------------------------

mysqlbackup: INFO: Creating 14 buffers each of size 65536.

150130 16:37:35 mysqlbackup: INFO: Apply-log operation starts with following threads

1 read-threads    1 process-threads

mysqlbackup: INFO: Using up to 100 MB of memory.

150130 16:37:35 mysqlbackup: INFO: ibbackup_logfile‘s creation parameters:

start lsn 1633280, end lsn 1633585,

start checkpoint 1633585.

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

mysqlbackup: INFO: InnoDB: Setting log file size to 50331648

mysqlbackup: INFO: InnoDB: Setting log file size to 50331648

150130 16:37:36 mysqlbackup: INFO: We were able to parse ibbackup_logfile up to

lsn 1633585.

150130 16:37:36 mysqlbackup: INFO: The first data file is ‘/home/backup/gflinux_20150130_16:37:30/datadir/ibdata1‘

and the new created log files are at ‘/home/backup/gflinux_20150130_16:37:30/datadir‘

150130 16:37:36 mysqlbackup: INFO: Apply-log operation completed successfully.

150130 16:37:36 mysqlbackup: INFO: Full backup prepared for recovery successfully.

mysqlbackup completed OK!

real0m6.225s

user0m0.023s

sys0m0.659s

[[email protected] backup]#

四、监控:

mysqlbackup的命令结果除了以文本形式输出外,相关信息也被记录到mysql模式中:

mysql> select * from backup_history\G;

*************************** 1. row ***************************

backup_id: 14226039516325379

tool_name: mysqlbackup --user=root --password=xxxxxx --backup-dir=/home/backup/test1 backup-and-apply-log

start_time: 2015-01-30 15:45:51

end_time: 2015-01-30 15:45:56

binlog_pos: -1

binlog_file: BINLOG-DISABLED

compression_level: 0

engines: MEMORY:MyISAM:CSV:InnoDB:PERFORMANCE_SCHEMA:

innodb_data_file_path: ibdata1:12M:autoextend

innodb_file_format: Antelope

start_lsn: 1633280

end_lsn: 1633585

incremental_base_lsn: 0

backup_type: FULL

backup_format: DIRECTORY

mysql_data_dir: /opt/mysql/data/

innodb_data_home_dir:

innodb_log_group_home_dir: /opt/mysql/data/

innodb_log_files_in_group: 2

innodb_log_file_size: 50331648

backup_destination: /home/backup/test1

lock_time: 2.444

exit_state: SUCCESS

last_error: NO_ERROR

last_error_code: 0

1 row in set (0.00 sec)

ERROR:

No query specified

mysql> select * from backup_progress where backup_id=14226039516325379\G;

*************************** 1. row ***************************

backup_id: 14226039516325379

tool_name: mysqlbackup

error_code: 0

error_message: NO_ERROR

current_time: 2015-01-30 15:45:53

current_state: Started mysqlbackup.

*************************** 2. row ***************************

backup_id: 14226039516325379

tool_name: mysqlbackup

error_code: 0

error_message: NO_ERROR

current_time: 2015-01-30 15:45:54

current_state: mysqlbackup locking tables and copying .frm + other engines data.

*************************** 3. row ***************************

backup_id: 14226039516325379

tool_name: mysqlbackup

error_code: 0

error_message: NO_ERROR

current_time: 2015-01-30 15:45:56

current_state: mysqlbackup unlocked the tables.

*************************** 4. row ***************************

backup_id: 14226039516325379

tool_name: mysqlbackup

error_code: 0

error_message: NO_ERROR

current_time: 2015-01-30 15:45:56

current_state: mysqlbackup returns success.

*************************** 5. row ***************************

backup_id: 14226039516325379

tool_name: mysqlbackup

error_code: 0

error_message: NO_ERROR

current_time: 2015-01-30 15:45:56

current_state: mysqlbackup applying log.

5 rows in set (0.00 sec)

这个可以使用--no-history-logging选项来终止。

五、恢复

[[email protected] gflinux_20150130_16:37:30]# mysqlbackup --backup-dir=/home/backup/gflinux_20150130_16:37:30 copy-back-and-apply-log

MySQL Enterprise Backup version 3.11.1 Linux-2.6.18-92.1.10.el5-i686 [2014/11/04]

Copyright (c) 2003, 2014, Oracle and/or its affiliates. All Rights Reserved.

mysqlbackup: INFO: Starting with following command line ...

mysqlbackup --backup-dir=/home/backup/gflinux_20150130_16:37:30

copy-back-and-apply-log

mysqlbackup: INFO:

IMPORTANT: Please check that mysqlbackup run completes successfully.

At the end of a successful ‘copy-back-and-apply-log‘ run mysqlbackup

prints "mysqlbackup completed OK!".

150130 16:58:40 mysqlbackup: INFO: MEB logfile created at /home/backup/gflinux_20150130_16:37:30/meta/MEB_2015-01-30.16-58-40_copy_back_dir_to_datadir.log

mysqlbackup: WARNING: If you restore to a server of a different version, the innodb_data_file_path parameter might have a different default. In that case you need to add ‘innodb_data_file_path=ibdata1:12M:autoextend‘ to the target server configuration.

mysqlbackup: WARNING: If you restore to a server of a different version, the innodb_log_files_in_group parameter might have a different default. In that case you need to add ‘innodb_log_files_in_group=2‘ to the target server configuration.

mysqlbackup: WARNING: If you restore to a server of a different version, the innodb_log_file_size parameter might have a different default. In that case you need to add ‘innodb_log_file_size=50331648‘ to the target server configuration.

--------------------------------------------------------------------

Server Repository Options:

--------------------------------------------------------------------

datadir = /opt/mysql/data

innodb_data_home_dir = /opt/mysql/data

innodb_data_file_path = ibdata1:12M:autoextend

innodb_log_group_home_dir = /opt/mysql/data

innodb_log_files_in_group = 2

innodb_log_file_size = 50331648

innodb_page_size = Null

innodb_checksum_algorithm = innodb

--------------------------------------------------------------------

Backup Config Options:

--------------------------------------------------------------------

datadir = /home/backup/gflinux_20150130_16:37:30/datadir

innodb_data_home_dir = /home/backup/gflinux_20150130_16:37:30/datadir

innodb_data_file_path = ibdata1:12M:autoextend

innodb_log_group_home_dir = /home/backup/gflinux_20150130_16:37:30/datadir

innodb_log_files_in_group = 2

innodb_log_file_size = 50331648

innodb_page_size = 16384

innodb_checksum_algorithm = innodb

mysqlbackup: INFO: Creating 14 buffers each of size 16777216.

150130 16:58:40 mysqlbackup: INFO: Copy-back-and-apply-log operation starts with following threads

1 read-threads    1 write-threads

mysqlbackup: INFO: Could not find binlog index file. binlogs will not be copied for this backup.

Point-In-Time-Recovery will not be possible.

If this is online backup then server may not have started with --log-bin.

You may specify its location with --log-bin-index option.

150130 16:58:41 mysqlbackup: INFO: Copying /home/backup/gflinux_20150130_16:37:30/datadir/ibdata1.

150130 16:58:41 mysqlbackup: INFO: Copying /home/backup/gflinux_20150130_16:37:30/datadir/mysql/innodb_index_stats.ibd.

150130 16:58:41 mysqlbackup: INFO: Copying /home/backup/gflinux_20150130_16:37:30/datadir/mysql/innodb_table_stats.ibd.

150130 16:58:41 mysqlbackup: INFO: Copying /home/backup/gflinux_20150130_16:37:30/datadir/mysql/slave_master_info.ibd.

150130 16:58:41 mysqlbackup: INFO: Copying /home/backup/gflinux_20150130_16:37:30/datadir/mysql/slave_relay_log_info.ibd.

150130 16:58:41 mysqlbackup: INFO: Copying /home/backup/gflinux_20150130_16:37:30/datadir/mysql/slave_worker_info.ibd.

150130 16:58:41 mysqlbackup: INFO: Copying /home/backup/gflinux_20150130_16:37:30/datadir/test/t.ibd.

150130 16:58:41 mysqlbackup: INFO: Copying the database directory ‘mysql‘

150130 16:58:42 mysqlbackup: INFO: Copying the database directory ‘performance_schema‘

150130 16:58:42 mysqlbackup: INFO: Copying the database directory ‘test‘

150130 16:58:42 mysqlbackup: INFO: Completing the copy of all non-innodb files.

150130 16:58:43 mysqlbackup: INFO: Apply-log operation has already been done on that backup.

150130 16:58:43 mysqlbackup: INFO: Creating server config files server-my.cnf and server-all.cnf in /opt/mysql/data

150130 16:58:43 mysqlbackup: INFO: Copy-back operation completed successfully.

mysqlbackup completed OK! with 3 warnings

[[email protected] gflinux_20150130_16:37:30]#

六、设置权限

设置mysql权限:

[[email protected] data]# chown -R mysql:mysql test

[[email protected] data]# ll

total 110724

-rw-rw---- 1 mysql mysql       56 Jan 27 15:15 auto.cnf

-rw-rw---- 1 mysql mysql 12582912 Jan 30 16:55 ibdata1

-rw-rw---- 1 mysql mysql 50331648 Jan 30 16:55 ib_logfile0

-rw-rw---- 1 mysql mysql 50331648 Jan 27 15:15 ib_logfile1

drwx------ 2 mysql mysql     4096 Jan 30 15:45 mysql

drwx------ 2 mysql mysql     4096 Jan 27 15:15 performance_schema

[[email protected] data]# ll

total 110752

-rw-rw---- 1 mysql mysql       56 Jan 27 15:15 auto.cnf

-rw-r--r-- 1 root  root       264 Jan 30 16:58 backup_variables.txt

-rw-rw---- 1 mysql mysql 12582912 Jan 30 16:58 ibdata1

-rw-rw---- 1 mysql mysql 50331648 Jan 30 16:55 ib_logfile0

-rw-rw---- 1 mysql mysql 50331648 Jan 27 15:15 ib_logfile1

drwx------ 2 mysql mysql     4096 Jan 30 15:45 mysql

drwx------ 2 mysql mysql     4096 Jan 27 15:15 performance_schema

-rw-r--r-- 1 root  root     12559 Jan 30 16:58 server-all.cnf

-rw-r--r-- 1 root  root      3201 Jan 30 16:58 server-my.cnf

drwx------ 2 root  root      4096 Jan 30 16:58 test

七、重启服务

[[email protected] data]# service mysqld start

Starting MySQL....                                         [  OK  ]

[[email protected] data]#

mysql> select count(*),now() from t;

+----------+---------------------+

| count(*) | now()               |

+----------+---------------------+

|        2 | 2015-01-30 17:05:44 |

+----------+---------------------+

1 row in set (0.00 sec)

mysql> select count(*),now() from t;

+----------+---------------------+

| count(*) | now()               |

+----------+---------------------+

|        2 | 2015-01-30 17:06:08 |

+----------+---------------------+

1 row in set (0.00 sec)

时间: 2024-10-04 02:04:42

MySQL的企业备份(MEB)的相关文章

企业备份恢复案例

在MySQl中我们备份数据一般有几种方式 热备份                         温备份                           冷备份 热备份指的是当数据库进行备份时, 数据库的读写操作均不是受影响 温备份指的是当数据库进行备份时, 数据库的读操作可以执行, 但是不能执行写操作 冷备份指的是当数据库进行备份时, 数据库不能进行读写操作, 即数据库要下线 这里我们说个MYSQL数据库的备份与恢复的企业案例 条件: 1.具备全量备份(mysqldump). 2.除全量备

MySQL优化之——备份和恢复

转载请注明出处:http://blog.csdn.net/l1028386804/article/details/46766919 备份 逻辑备份方法 使用MYSQLDUMP命令备份 MYSQLDUMP是MYSQL提供的一个非常有用的数据库备份工具.mysqldump命令执行时将数据库备份成一个文本文件,该文件中实际上包含了多个CREATE 和INSERT语句,使用这些语句可以重新创建表和插入数据 MYSQLDUMP的语法和选项 mysqldump -u user -p pwd -h host

mysql 数据库定时备份 增量/全备份

实验楼的 MySQL 数据库需要设计一个自动备份方案,能够每周执行一次全备份,每天执行一次增量备份. 数据库名称为 shiyanlou,管理的用户名为 shiyanlou,密码为 shiyanlou.注意需要先手动启动 MySQL 服务. 目标 设计并实现备份方案,任务完成后满足以下要求: MySQL 服务处于运行状态 需要为服务器中的 shiyanlou 用户设定计划任务 计划任务中设定每周的周一凌晨3点执行一次全备份 计划任务中设定每天凌晨3点执行一次增量备份,周一不执行 请不要编写额外的脚

再谈MySQL全库备份

再谈MySQL全库备份 简介 Part1:写在最前 在很早之前,我写过一个MySQL生产库全库备份脚本,今天有同事问我是不是要再加一个-R参数来备份存储过程,理由的话是由于mysqldump --help中 关于存储过程的默认备份是false. routines                          FALSE MySQL生产库全库备份脚本 http://suifu.blog.51cto.com/9167728/1758022 实战 Part1:写在最前 我备份一般就三个参数 --s

mysql全库备份/增量备份脚本

http://hongge.blog.51cto.com/ 生产环境中Mysql数据库的备份是周期性重复的操作,所以通常是要编写脚本实现,通过crond计划任务周期性执行备份脚本 mysqldump备份方案: 周日凌晨1点全库备份 周一到周六凌晨每隔4个小时增量备份一次 设置crontab任务,每天执行备份脚本 # crontab –e #每个星期日凌晨1:00执行完全备份脚本 0 1 * * 0 /root/mysqlfullbackup.sh >/dev/null 2>&1 #周一

MySQL数据库-完全备份及恢复

MySQL数据库-完全备份及恢复 数据库备份的分类 物理角度: 冷备份:也称脱机备份,特点:关掉数据库再备份 热备份:也称联机备份,特点:开启数据库再备份 温备份:数据库只有可读权限的状态下备份 逻辑角度: 对数据库的对象的备份,例如数据表,及数据表中的一些sql语句等 备份策略角度: 完全备份:每次对数据进行整体的备份 差异备份:在第一次完整备份a数据后,以后的每次的备份是a+b,b就是针对于a数据发生变化的数据,称之为'差异数据'.缺点:b的数据内存会越来越大b+=b,导致数据恢复缓慢.恢复

mysql 全量备份和增量备份

mysql 全量备份: vim /root/mysql_bakup.sh #!/bin/bash #Date:2017/5/2 #Author:wangpengtai #Blog:http://wangpengtai.blog.51cto.com #At Sunday, we will backup the completed databases and the incresed binary log during Saturday to Sunday. #In other weekdays, 

MySQL的逻辑备份(mydumper+mysqldump)

虽说MySQL的逻辑备份经常会由于锁表等缺陷遭到诟病, 实际上在停机窗口时间内, 如果数据量不是太高的话, 做逻辑备份还是挺简单的~ 准备工作:1. 目标库(从这个库备份数据)先要有足够权限的账号(临时的root就可以了~用完就删);2. 对应的工具要安装好, 如mydumper;3. 准备好脚本/命令, 不放心就在测试环境演练一下~ 一切准备就绪之后就可以等停机了~ 这里记下备份&恢复用的命令: 备份: nohup mysqldump -h<host> -u<user>

MySQL的数据备份以及pymysql的使用

一.MySQL的数据备份 语法: # mysqldump -h 服务器 -u用户名 -p密码 数据库名 > 备份文件.sql #示例: #单库备份 mysqldump -uroot -p123 db1 > db1.sql mysqldump -uroot -p123 db1 table1 table2 > db1-table1-table2.sql #多库备份 mysqldump -uroot -p123 --databases db1 db2 mysql db3 > db1_db