0. xtrabackup的功能
能实现的功能:
非阻塞备份innodb等事务引擎数据库、
备份myisam表会阻塞(需要锁)、
支持全备、增量备份、压缩备份、
快速增量备份(xtradb,原理类似于oracle:tracking 上次备份之后发生修改的page.)、
percona支持归档redo log的备份、
percona5.6+支持轻量级的backup-lock替代原来重量级的FTWRL,此时即使备份非事务引擎表也不会阻塞innodb的DML语句了、
支持加密备份、流备份(备份到远程机器)、并行本地备份、并行压缩、并行加密、并行应用备份期间产生的redo日志、并行copy-back
支持部分备份,只备份某个库,某个表
支持部分恢复
支持备份单个表分区
支持备份速度限制,指备份产生的IO速度的限制
支持point-in-time恢复
支持compat备份,也即使不备份索引数据,索引在prepare时--rebuild-indexs
支持备份buffer pool
支持单表export, import到其它库
支持 rsync 来缩短备份非事务引擎表的锁定时间
1. 物理备份需要的权限
使用innobackupex/xtrabackup进行备份,必须先配置好权限。需要的权限分为两部分:
1>系统层面的权限: 执行 innobackupex/xtrabackup 命令的Linux用户需要对mysql datadir和保存备份的目录有读写执行的权限,当然需要对这些命令要有执行权限;
2>mysqld层面的权限:innobackupex/xtrabackup --user=bkpuser 该用户bkpuser是指mysql.user表中的用户,不是系统层面的用户;需要一些基本的权限来执行备份过程:
最基本的权限:
create user 'bkpuser'@'localhost' identified by 'xxx';
grant reload,lock tables,replication client on *.* to 'bkpuser'@'localhost';
这些权限仅仅只能完成:全备,增量备份,恢复;
一般如果需要部分备份,export表,import表,还需要:grant create tablespace on *.* to 'bkpuser'@'localhost';
如果还需要对备份的过程中对锁进行一些优化,防止发生阻塞所有DML的情况,则还需要:
grant process,super on *.* to 'bkpuser'@'localhost';
  1. (root@localhost)[(none)]mysql>show grants for 'bkpuser'@'localhost'\G
  2. *************************** . row ***************************
  3. Grants for bkpuser@localhost: GRANT RELOAD, PROCESS, SUPER, LOCK TABLES, REPLICATION CLIENT, CREATE TABLESPACE ON *.* TO 'bkpuser'@'localhost' IDENTIFIED BY PASSWORD '*BDC62F68AF8F0B8BFAE27FF782C5D8CE9F4BAFCB'
  4. row in set (0.00 sec)

2. innobackupex 命令选项:

  1. [root@localhost ~]# innobackupex --help
  2. Open source backup tool for InnoDB and XtraDB
  3. [... ...]
  4. innobackupex - Non-blocking backup tool for InnoDB, XtraDB and HailDB databases
  5.  
  6. SYNOPOSIS(使用方法)
  7.  
  8. innobackupex [--compress] [--compress-threads=NUMBER-OF-THREADS] [--compress-chunk-size=CHUNK-SIZE]
  9. [--encrypt=ENCRYPTION-ALGORITHM] [--encrypt-threads=NUMBER-OF-THREADS] [--encrypt-chunk-size=CHUNK-SIZE]
  10. [--encrypt-key=LITERAL-ENCRYPTION-KEY] | [--encryption-key-file=MY.KEY]
  11. [--include=REGEXP] [--user=NAME]
  12. [--password=WORD] [--port=PORT] [--socket=SOCKET]
  13. [--no-timestamp] [--ibbackup=IBBACKUP-BINARY]
  14. [--slave-info] [--galera-info] [--stream=tar|xbstream]
  15. [--defaults-file=MY.CNF] [--defaults-group=GROUP-NAME]
  16. [--databases=LIST] [--no-lock]
  17. [--tmpdir=DIRECTORY] [--tables-file=FILE]
  18. [--history=NAME]
  19. [--incremental] [--incremental-basedir]
  20. [--incremental-dir] [--incremental-force-scan] [--incremental-lsn]
  21. [--incremental-history-name=NAME] [--incremental-history-uuid=UUID]
  22. [--close-files] [--compact]
  23. BACKUP-ROOT-DIR
  24.  
  25. innobackupex --apply-log [--use-memory=B]
  26. [--defaults-file=MY.CNF]
  27. [--export] [--redo-only] [--ibbackup=IBBACKUP-BINARY]
  28. BACKUP-DIR
  29.  
  30. innobackupex --copy-back [--defaults-file=MY.CNF] [--defaults-group=GROUP-NAME] BACKUP-DIR
  31.  
  32. innobackupex --move-back [--defaults-file=MY.CNF] [--defaults-group=GROUP-NAME] BACKUP-DIR
  33.  
  34. innobackupex [--decompress] [--decrypt=ENCRYPTION-ALGORITHM]
  35. [--encrypt-key=LITERAL-ENCRYPTION-KEY] | [--encryption-key-file=MY.KEY]
  36. [--parallel=NUMBER-OF-FORKS] BACKUP-DIR
  37.  
  38. DESCRIPTION
  39.  
  40. The first command line above makes a hot backup of a MySQL database.
  41. By default it creates a backup directory (named by the current date
  42. and time) in the given backup root directory. With the --no-timestamp
  43. option it does not create a time-stamped backup directory, but it puts
  44. the backup in the given directory (which must not exist). This
  45. command makes a complete backup of all MyISAM and InnoDB tables and
  46. indexes in all databases or in all of the databases specified with the
  47. --databases option. The created backup contains .frm, .MRG, .MYD,
  48. .MYI, .MAD, .MAI, .TRG, .TRN, .ARM, .ARZ, .CSM, CSV, .opt, .par, and
  49. InnoDB data and log files. The MY.CNF options file defines the
  50. location of the database. This command connects to the MySQL server
  51. using the mysql client program, and runs xtrabackup as a child
  52. process.
  53.  
  54. The --apply-log command prepares a backup for starting a MySQL
  55. server on the backup. This command recovers InnoDB data files as specified
  56. in BACKUP-DIR/backup-my.cnf using BACKUP-DIR/xtrabackup_logfile,
  57. and creates new InnoDB log files as specified in BACKUP-DIR/backup-my.cnf.
  58. The BACKUP-DIR should be the path to a backup directory created by
  59. xtrabackup. This command runs xtrabackup as a child process, but it does not
  60. connect to the database server.
  61.  
  62. The --copy-back command copies data, index, and log files
  63. from the backup directory back to their original locations.
  64. The MY.CNF options file defines the original location of the database.
  65. The BACKUP-DIR is the path to a backup directory created by xtrabackup.
  66.  
  67. The --move-back command is similar to --copy-back with the only difference that
  68. it moves files to their original locations rather than copies them. As this
  69. option removes backup files, it must be used with caution. It may be useful in
  70. cases when there is not enough free disk space to copy files.
  71.  
  72. The --decompress --decrypt command will decrypt and/or decompress a backup made
  73. with the --compress and/or --encrypt options. When decrypting, the encryption
  74. algorithm and key used when the backup was taken MUST be provided via the
  75. specified options. --decrypt and --decompress may be used together at the same
  76. time to completely normalize a previously compressed and encrypted backup. The
  77. --parallel option will allow multiple files to be decrypted and/or decompressed
  78. simultaneously. In order to decompress, the qpress utility MUST be installed
  79. and accessable within the path. This process will remove the original
  80. compressed/encrypted files and leave the results in the same location.
  81.  
  82. On success the exit code innobackupex is . A non-zero exit code
  83. indicates an error.
  84.  
  85. Usage: [innobackupex [--defaults-file=#] --backup | innobackupex [--defaults-file=#] --prepare] [OPTIONS]
  86. -v, --version print xtrabackup version information
  87. -?, --help This option displays a help screen and exits.
  88. --apply-log Prepare a backup in BACKUP-DIR by applying the
  89. transaction log file named "xtrabackup_logfile" located
  90. in the same directory. Also, create new transaction logs.
  91. The InnoDB configuration is read from the file
  92. "backup-my.cnf".
  93. --redo-only This option should be used when preparing the base full
  94. backup and when merging all incrementals except the last
  95. one. This forces xtrabackup to skip the "rollback" phase
  96. and do a "redo" only. This is necessary if the backup
  97. will have incremental changes applied to it later. See
  98. the xtrabackup documentation for details.
  99. --copy-back Copy all the files in a previously made backup from the
  100. backup directory to their original locations.
  101. --move-back Move all the files in a previously made backup from the
  102. backup directory to the actual datadir location. Use with
  103. caution, as it removes backup files.
  104. --galera-info This options creates the xtrabackup_galera_info file
  105. which contains the local node state at the time of the
  106. backup. Option should be used when performing the backup
  107. of Percona-XtraDB-Cluster. Has no effect when backup
  108. locks are used to create the backup.
  109. --slave-info This option is useful when backing up a replication slave
  110. server. It prints the binary log position and name of the
  111. master server. It also writes this information to the
  112. "xtrabackup_slave_info" file as a "CHANGE MASTER"
  113. command. A new slave for this master can be set up by
  114. starting a slave server on this backup and issuing a
  115. "CHANGE MASTER" command with the binary log position
  116. saved in the "xtrabackup_slave_info" file.
  117. --incremental This option tells xtrabackup to create an incremental
  118. backup, rather than a full one. It is passed to the
  119. xtrabackup child process. When this option is specified,
  120. either --incremental-lsn or --incremental-basedir can
  121. also be given. If neither option is given, option
  122. --incremental-basedir is passed to xtrabackup by default,
  123. set to the first timestamped backup directory in the
  124. backup base directory.
  125. --no-lock Use this option to disable table lock with "FLUSH TABLES
  126. WITH READ LOCK". Use it only if ALL your tables are
  127. InnoDB and you DO NOT CARE about the binary log position
  128. of the backup. This option shouldn't be used if there are
  129. any DDL statements being executed or if any updates are
  130. happening on non-InnoDB tables (this includes the system
  131. MyISAM tables in the mysql database), otherwise it could
  132. lead to an inconsistent backup. If you are considering to
  133. use --no-lock because your backups are failing to acquire
  134. the lock, this could be because of incoming replication
  135. events preventing the lock from succeeding. Please try
  136. using --safe-slave-backup to momentarily stop the
  137. replication slave thread, this may help the backup to
  138. succeed and you then don't need to resort to using this
  139. option.
  140. --safe-slave-backup Stop slave SQL thread and wait to start backup until
  141. Slave_open_temp_tables in "SHOW STATUS" is zero. If there
  142. are no open temporary tables, the backup will take place,
  143. otherwise the SQL thread will be started and stopped
  144. until there are no open temporary tables. The backup will
  145. fail if Slave_open_temp_tables does not become zero after
  146. --safe-slave-backup-timeout seconds. The slave SQL thread
  147. will be restarted when the backup finishes.
  148. --rsync Uses the rsync utility to optimize local file transfers.
  149. When this option is specified, innobackupex uses rsync to
  150. copy all non-InnoDB files instead of spawning a separate
  151. cp for each file, which can be much faster for servers
  152. with a large number of databases or tables. This option
  153. cannot be used together with --stream.
  154. --force-non-empty-directories
  155. This option, when specified, makes --copy-back or
  156. --move-back transfer files to non-empty directories. Note
  157. that no existing files will be overwritten. If
  158. --copy-back or --nove-back has to copy a file from the
  159. backup directory which already exists in the destination
  160. directory, it will still fail with an error.
  161. --no-timestamp This option prevents creation of a time-stamped
  162. subdirectory of the BACKUP-ROOT-DIR given on the command
  163. line. When it is specified, the backup is done in
  164. BACKUP-ROOT-DIR instead.
  165. --no-version-check This option disables the version check which is enabled
  166. by the --version-check option.
  167. --no-backup-locks This option controls if backup locks should be used
  168. instead of FLUSH TABLES WITH READ LOCK on the backup
  169. stage. The option has no effect when backup locks are not
  170. supported by the server. This option is enabled by
  171. default, disable with --no-backup-locks.
  172. --decompress Decompresses all files with the .qp extension in a backup
  173. previously made with the --compress option.
  174. --user=name This option specifies the MySQL username used when
  175. connecting to the server, if that's not the current user.
  176. The option accepts a string argument. See mysql --help
  177. for details.
  178. --host=name This option specifies the host to use when connecting to
  179. the database server with TCP/IP. The option accepts a
  180. string argument. See mysql --help for details.
  181. --port=# This option specifies the port to use when connecting to
  182. the database server with TCP/IP. The option accepts a
  183. string argument. See mysql --help for details.
  184. --password=name This option specifies the password to use when connecting
  185. to the database. It accepts a string argument. See mysql
  186. --help for details.
  187. --socket=name This option specifies the socket to use when connecting
  188. to the local database server with a UNIX domain socket.
  189. The option accepts a string argument. See mysql --help
  190. for details.
  191. --incremental-history-name=name
  192. This option specifies the name of the backup series
  193. stored in the PERCONA_SCHEMA.xtrabackup_history history
  194. record to base an incremental backup on. Xtrabackup will
  195. search the history table looking for the most recent
  196. (highest innodb_to_lsn), successful backup in the series
  197. and take the to_lsn value to use as the starting lsn for
  198. the incremental backup. This will be mutually exclusive
  199. with --incremental-history-uuid, --incremental-basedir
  200. and --incremental-lsn. If no valid lsn can be found (no
  201. series by that name, no successful backups by that name)
  202. xtrabackup will return with an error. It is used with the
  203. --incremental option.
  204. --incremental-history-uuid=name
  205. This option specifies the UUID of the specific history
  206. record stored in the PERCONA_SCHEMA.xtrabackup_history to
  207. base an incremental backup on.
  208. --incremental-history-name, --incremental-basedir and
  209. --incremental-lsn. If no valid lsn can be found (no
  210. success record with that uuid) xtrabackup will return
  211. with an error. It is used with the --incremental option.
  212. --decrypt=name Decrypts all files with the .xbcrypt extension in a
  213. backup previously made with --encrypt option.
  214. --ftwrl-wait-query-type=name
  215. This option specifies which types of queries are allowed
  216. to complete before innobackupex will issue the global
  217. lock. Default is all.
  218. --kill-long-query-type=name
  219. This option specifies which types of queries should be
  220. killed to unblock the global lock. Default is "all".
  221. --history[=name] This option enables the tracking of backup history in the
  222. PERCONA_SCHEMA.xtrabackup_history table. An optional
  223. history series name may be specified that will be placed
  224. with the history record for the current backup being
  225. taken.
  226. --include=name This option is a regular expression to be matched against
  227. table names in databasename.tablename format. It is
  228. passed directly to xtrabackup's --tables option. See the
  229. xtrabackup documentation for details.
  230. --databases=name This option specifies the list of databases that
  231. innobackupex should back up. The option accepts a string
  232. argument or path to file that contains the list of
  233. databases to back up. The list is of the form
  234. "databasename1[.table_name1] databasename2[.table_name2]
  235. . . .". If this option is not specified, all databases
  236. containing MyISAM and InnoDB tables will be backed up.
  237. Please make sure that --databases contains all of the
  238. InnoDB databases and tables, so that all of the
  239. innodb.frm files are also backed up. In case the list is
  240. very long, this can be specified in a file, and the full
  241. path of the file can be specified instead of the list.
  242. (See option --tables-file.)
  243. --kill-long-queries-timeout=#
  244. This option specifies the number of seconds innobackupex
  245. waits between starting FLUSH TABLES WITH READ LOCK and
  246. killing those queries that block it. Default is
  247. seconds, which means innobackupex will not attempt to
  248. kill any queries.
  249. --ftwrl-wait-timeout=#
  250. This option specifies time in seconds that innobackupex
  251. should wait for queries that would block FTWRL before
  252. running it. If there are still such queries when the
  253. timeout expires, innobackupex terminates with an error.
  254. Default is , in which case innobackupex does not wait
  255. for queries to complete and starts FTWRL immediately.
  256. --ftwrl-wait-threshold=#
  257. This option specifies the query run time threshold which
  258. is used by innobackupex to detect long-running queries
  259. with a non-zero value of --ftwrl-wait-timeout. FTWRL is
  260. not started until such long-running queries exist. This
  261. option has no effect if --ftwrl-wait-timeout is .
  262. Default value is seconds.
  263. --debug-sleep-before-unlock=#
  264. This is a debug-only option used by the XtraBackup test
  265. suite.
  266. --safe-slave-backup-timeout=#
  267. How many seconds --safe-slave-backup should wait for
  268. Slave_open_temp_tables to become zero. (default )
  269. --close-files Do not keep files opened. This option is passed directly
  270. to xtrabackup. Use at your own risk.
  271. --compact Create a compact backup with all secondary index pages
  272. omitted. This option is passed directly to xtrabackup.
  273. See xtrabackup documentation for details.
  274. --compress[=name] This option instructs xtrabackup to compress backup
  275. copies of InnoDB data files. It is passed directly to the
  276. xtrabackup child process. Try 'xtrabackup --help' for
  277. more details.
  278. --compress-threads=#
  279. This option specifies the number of worker threads that
  280. will be used for parallel compression. It is passed
  281. directly to the xtrabackup child process. Try 'xtrabackup
  282. --help' for more details.
  283. --compress-chunk-size=#
  284. Size of working buffer(s) for compression threads in
  285. bytes. The default value is 64K.
  286. --encrypt=name This option instructs xtrabackup to encrypt backup copies
  287. of InnoDB data files using the algorithm specified in the
  288. ENCRYPTION-ALGORITHM. It is passed directly to the
  289. xtrabackup child process. Try 'xtrabackup --help' for
  290. more details.
  291. --encrypt-key=name This option instructs xtrabackup to use the given
  292. ENCRYPTION-KEY when using the --encrypt or --decrypt
  293. options. During backup it is passed directly to the
  294. xtrabackup child process. Try 'xtrabackup --help' for
  295. more details.
  296. --encrypt-key-file=name
  297. This option instructs xtrabackup to use the encryption
  298. key stored in the given ENCRYPTION-KEY-FILE when using
  299. the --encrypt or --decrypt options.
  300. --encrypt-threads=# This option specifies the number of worker threads that
  301. will be used for parallel encryption. It is passed
  302. directly to the xtrabackup child process. Try 'xtrabackup
  303. --help' for more details.
  304. --encrypt-chunk-size=#
  305. This option specifies the size of the internal working
  306. buffer for each encryption thread, measured in bytes. It
  307. is passed directly to the xtrabackup child process. Try
  308. 'xtrabackup --help' for more details.
  309. --export This option is passed directly to xtrabackup's --export
  310. option. It enables exporting individual tables for import
  311. into another server. See the xtrabackup documentation for
  312. details.
  313. --extra-lsndir=name This option specifies the directory in which to save an
  314. extra copy of the "xtrabackup_checkpoints" file. The
  315. option accepts a string argument. It is passed directly
  316. to xtrabackup's --extra-lsndir option. See the xtrabackup
  317. documentation for details.
  318. --incremental-basedir=name
  319. This option specifies the directory containing the full
  320. backup that is the base dataset for the incremental
  321. backup. The option accepts a string argument. It is used
  322. with the --incremental option.
  323. --incremental-dir=name
  324. This option specifies the directory where the incremental
  325. backup will be combined with the full backup to make a
  326. new full backup. The option accepts a string argument.
  327. It is used with the --incremental option.
  328. --incremental-force-scan
  329. This options tells xtrabackup to perform full scan of
  330. data files for taking an incremental backup even if full
  331. changed page bitmap data is available to enable the
  332. backup without the full scan.
  333. --log-copy-interval=#
  334. This option specifies time interval between checks done
  335. by log copying thread in milliseconds.
  336. --incremental-lsn=name
  337. This option specifies the log sequence number (LSN) to
  338. use for the incremental backup. The option accepts a
  339. string argument. It is used with the --incremental
  340. option. It is used instead of specifying
  341. --incremental-basedir. For databases created by MySQL and
  342. Percona Server 5.0-series versions, specify the LSN as
  343. two -bit integers in high:low format. For databases
  344. created in 5.1 and later, specify the LSN as a single
  345. -bit integer.
  346. --parallel=# On backup, this option specifies the number of threads
  347. the xtrabackup child process should use to back up files
  348. concurrently. The option accepts an integer argument. It
  349. is passed directly to xtrabackup's --parallel option. See
  350. the xtrabackup documentation for details.
  351. --rebuild-indexes This option only has effect when used together with the
  352. --apply-log option and is passed directly to xtrabackup.
  353. When used, makes xtrabackup rebuild all secondary indexes
  354. after applying the log. This option is normally used to
  355. prepare compact backups. See the XtraBackup manual for
  356. more information.
  357. --rebuild-threads=# Use this number of threads to rebuild indexes in a
  358. compact backup. Only has effect with --prepare and
  359. --rebuild-indexes.
  360. --stream=name This option specifies the format in which to do the
  361. streamed backup. The option accepts a string argument.
  362. The backup will be done to STDOUT in the specified
  363. format. Currently, the only supported formats are tar and
  364. xbstream. This option is passed directly to xtrabackup's
  365. --stream option.
  366. --tables-file=name This option specifies the file in which there are a list
  367. of names of the form database. The option accepts a
  368. string argument.table, one per line. The option is passed
  369. directly to xtrabackup's --tables-file option.
  370. --throttle=# This option specifies a number of I/O operations (pairs
  371. of read+write) per second. It accepts an integer
  372. argument. It is passed directly to xtrabackup's
  373. --throttle option.
  374. -t, --tmpdir=name This option specifies the location where a temporary
  375. files will be stored. If the option is not specified, the
  376. default is to use the value of tmpdir read from the
  377. server configuration.
  378. --use-memory=# This option accepts a string argument that specifies the
  379. amount of memory in bytes for xtrabackup to use for crash
  380. recovery while preparing a backup. Multiples are
  381. supported providing the unit (e.g. 1MB, 1GB). It is used
  382. only with the option --apply-log. It is passed directly
  383. to xtrabackup's --use-memory option. See the xtrabackup
  384. documentation for details.
  385. [root@localhost ~]#

innobackupex --help

3. 使用 innobackupex 备份
3.1 全备
(这里系统层面使用的root用户备份,msyql层面使用的是bkpuser用户,root需要对datadir /var/lib/mysql, 备份目录/backup/xtrabackup/full有读写执行权限;bkpuser也需在mysql中有相关权限)
[root@localhost ~]# innobackupex  /backup/xtrabackup/full --user=bkpuser --password=digdeep
  1. [root@localhost ~]# innobackupex /backup/xtrabackup/full --user=bkpuser --password=digdeep
  2. :: innobackupex: Starting the backup operation
  3.  
  4. IMPORTANT: Please check that the backup run completes successfully.
  5. At the end of a successful backup run innobackupex
  6. prints "completed OK!".
  7.  
  8. :: version_check Connecting to MySQL server with DSN 'dbi:mysql:;mysql_read_default_group=xtrabackup;mysql_socket=/tmp/mysql.sock' as 'bkpuser' (using password: YES).
  9. :: version_check Connected to MySQL server
  10. :: version_check Executing a version check against the server...
  11. :: version_check Done.
  12. :: Connecting to MySQL server host: localhost, user: bkpuser, password: set, port: , socket: /tmp/mysql.sock
  13. Using server version 5.6.-log
  14. innobackupex version 2.3. based on MySQL server 5.6. Linux (i686) (revision id: 306a2e0)
  15. xtrabackup: uses posix_fadvise().
  16. xtrabackup: cd to /var/lib/mysql
  17. xtrabackup: open files limit requested , set to
  18. xtrabackup: using the following InnoDB configuration:
  19. xtrabackup: innodb_data_home_dir = ./
  20. xtrabackup: innodb_data_file_path = ibdata1:12M:autoextend
  21. xtrabackup: innodb_log_group_home_dir = ./
  22. xtrabackup: innodb_log_files_in_group =
  23. xtrabackup: innodb_log_file_size =
  24. :: >> log scanned up to ()
  25. xtrabackup: Generating a list of tablespaces
  26. :: [] Copying ./ibdata1 to /backup/xtrabackup/full/--05_22--/ibdata1
  27. :: >> log scanned up to ()
  28. :: >> log scanned up to ()
  29. :: [] ...done
  30. :: [] Copying ./mysql/slave_master_info.ibd to /backup/xtrabackup/full/--05_22--/mysql/slave_master_info.ibd
  31. :: [] ...done
  32. :: [] Copying ./mysql/innodb_index_stats.ibd to /backup/xtrabackup/full/--05_22--/mysql/innodb_index_stats.ibd
  33. :: [] ...done
  34. [... ...]
  35. :: [] Copying ./aazj/group_union.ibd to /backup/xtrabackup/full/--05_22--/aazj/group_union.ibd
  36. :: [] ...done
  37. :: [] Copying ./aazj/SYS_PARAM.ibd to /backup/xtrabackup/full/--05_22--/aazj/SYS_PARAM.ibd
  38. :: >> log scanned up to ()
  39. :: [] ...done
  40. :: [] Copying ./aazj/GroupBlog.ibd to /backup/xtrabackup/full/--05_22--/aazj/GroupBlog.ibd
  41. :: [] ...done
  42. [... ...]
  43. :: [] Copying ./aazj/Accounting_paylog.ibd to /backup/xtrabackup/full/--05_22--/aazj/Accounting_paylog.ibd
  44. :: [] ...done
  45. :: [] Copying ./aazj/Customer.ibd to /backup/xtrabackup/full/--05_22--/aazj/Customer.ibd
  46. :: [] ...done
  47. :: [] Copying ./aazj/uuu.ibd to /backup/xtrabackup/full/--05_22--/aazj/uuu.ibd
  48. :: >> log scanned up to ()
  49. :: >> log scanned up to ()
  50. :: >> log scanned up to ()
  51. :: [] ...done
  52. :: [] Copying ./aazj/Members.ibd to /backup/xtrabackup/full/--05_22--/aazj/Members.ibd
  53. :: [] ...done
  54. :: [] Copying ./aazj/tttt.ibd to /backup/xtrabackup/full/--05_22--/aazj/tttt.ibd
  55. :: [] ...done
  56. :: [] Copying ./aazj/uu_test.ibd to /backup/xtrabackup/full/--05_22--/aazj/uu_test.ibd
  57. :: >> log scanned up to ()
  58. :: >> log scanned up to ()
  59. :: >> log scanned up to ()
  60. :: >> log scanned up to ()
  61. :: [] ...done
  62. :: [] Copying ./aazj/Mess_Receive.ibd to /backup/xtrabackup/full/--05_22--/aazj/Mess_Receive.ibd
  63. :: [] ...done
  64. [... ...]
  65. :: >> log scanned up to ()
  66. Executing FLUSH NO_WRITE_TO_BINLOG TABLES...
  67. :: Executing FLUSH TABLES WITH READ LOCK...
  68. :: Starting to backup non-InnoDB tables and files
  69. :: [] Copying ./mysql/columns_priv.frm to /backup/xtrabackup/full/--05_22--/mysql/columns_priv.frm
  70. :: [] ...done
  71. :: [] Copying ./mysql/user.MYI to /backup/xtrabackup/full/--05_22--/mysql/user.MYI
  72. :: [] ...done
  73. [... ...]
  74. :: [] Copying ./mysql/help_category.frm to /backup/xtrabackup/full/--05_22--/mysql/help_category.frm
  75. :: [] ...done
  76. :: >> log scanned up to ()
  77. :: [] Copying ./mysql/proc.MYD to /backup/xtrabackup/full/--05_22--/mysql/proc.MYD
  78. :: [] ...done
  79. [... ...]
  80. :: [] ...done
  81. :: [] Copying ./mysql/proxies_priv.MYI to /backup/xtrabackup/full/--05_22--/mysql/proxies_priv.MYI
  82. :: [] ...done
  83. :: [] Copying ./aazj/model_order.frm to /backup/xtrabackup/full/--05_22--/aazj/model_order.frm
  84. :: [] ...done
  85. :: [] Copying ./aazj/Comment.frm to /backup/xtrabackup/full/--05_22--/aazj/Comment.frm
  86. :: [] ...done
  87. [... ...]
  88. :: [] Copying ./performance_schema/events_waits_summary_by_host_by_event_name.frm to /backup/xtrabackup/full/--05_22--/performance_schema/events_waits_summary_by_host_by_event_name.frm
  89. :: [] ...done
  90. [... ...]
  91. :: [] Copying ./performance_schema/events_statements_summary_by_account_by_event_name.frm to /backup/xtrabackup/full/--05_22--/performance_schema/events_statements_summary_by_account_by_event_name.frm
  92. :: [] ...done
  93. :: [] Copying ./t/city.frm to /backup/xtrabackup/full/--05_22--/t/city.frm
  94. :: [] ...done
  95. :: [] Copying ./t/db.opt to /backup/xtrabackup/full/--05_22--/t/db.opt
  96. :: [] ...done
  97. :: [] Copying ./t/t.frm to /backup/xtrabackup/full/--05_22--/t/t.frm
  98. :: [] ...done
  99. :: Finished backing up non-InnoDB tables and files
  100. :: [] Writing xtrabackup_binlog_info
  101. :: [] ...done
  102. :: Executing FLUSH NO_WRITE_TO_BINLOG ENGINE LOGS...
  103. xtrabackup: The latest check point (for incremental): '731686008'
  104. xtrabackup: Stopping log copying thread.
  105. . :: >> log scanned up to ()
  106.  
  107. :: Executing UNLOCK TABLES
  108. :: All tables unlocked
  109. :: Backup created in directory '/backup/xtrabackup/full/2015-11-05_22-38-55'
  110. MySQL binlog position: filename 'mysql-bin.000015', position '117940'
  111. :: [] Writing backup-my.cnf
  112. :: [] ...done
  113. :: [] Writing xtrabackup_info
  114. :: [] ...done
  115. xtrabackup: Transaction log of lsn () to () was copied.
  116. :: completed OK!
3.2 恢复
1> 第一步prepare(两次prepare,第一次应用备份期间产生的redo log,进行前滚和回滚:replay在redo log中已经提交的事务,rollback没有提交的事务)
注意这里的路径,必须要包括最后那个timestamp目录,不然会下面的错误:
  1. [root@localhost ~]# innobackupex --apply-log /backup/xtrabackup/full/ --user=bkpuser --password=digdeep
  2. :: innobackupex: Starting the apply-log operation
  3.  
  4. IMPORTANT: Please check that the apply-log run completes successfully.
  5. At the end of a successful apply-log run innobackupex
  6. prints "completed OK!".
  7.  
  8. innobackupex version 2.3. based on MySQL server 5.6. Linux (i686) (revision id: 306a2e0)
  9. xtrabackup: cd to /backup/xtrabackup/full
  10. xtrabackup: Error: cannot open ./xtrabackup_checkpoints
  11. xtrabackup: error: xtrabackup_read_metadata()
  12. xtrabackup: This target seems not to have correct metadata...
  13. -- :: b771e6d0 InnoDB: Operating system error number in a file operation.
  14. InnoDB: The error means the system cannot find the path specified.
  15. xtrabackup: Warning: cannot open ./xtrabackup_logfile. will try to find.
  16. -- :: b771e6d0 InnoDB: Operating system error number in a file operation.
  17. InnoDB: The error means the system cannot find the path specified.
  18. xtrabackup: Fatal error: cannot find ./xtrabackup_logfile.
  19. xtrabackup: Error: xtrabackup_init_temp_log() failed.
--apply-log会调用 xtrabackup --prepare两次,第一次前滚和回滚,第二次生成iblogfile[0|1]
[root@localhost ~]# innobackupex --apply-log /backup/xtrabackup/full/2015-11-05_22-38-55/ --user=bkpuser --password=digdeep
  1. [root@localhost ~]# innobackupex --apply-log /backup/xtrabackup/full/2015-11-05_22-38-55/ --user=bkpuser --password=digdeep
  2. :: innobackupex: Starting the apply-log operation
  3.  
  4. IMPORTANT: Please check that the apply-log run completes successfully.
  5. At the end of a successful apply-log run innobackupex
  6. prints "completed OK!".
  7.  
  8. innobackupex version 2.3. based on MySQL server 5.6. Linux (i686) (revision id: 306a2e0)
  9. xtrabackup: cd to /backup/xtrabackup/full/--05_22--/
  10. xtrabackup: This target seems to be not prepared yet.
  11. xtrabackup: xtrabackup_logfile detected: size=, start_lsn=()
  12. xtrabackup: using the following InnoDB configuration for recovery:
  13. xtrabackup: innodb_data_home_dir = ./
  14. xtrabackup: innodb_data_file_path = ibdata1:10M:autoextend
  15. xtrabackup: innodb_log_group_home_dir = ./
  16. xtrabackup: innodb_log_files_in_group =
  17. xtrabackup: innodb_log_file_size =
  18. xtrabackup: using the following InnoDB configuration for recovery:
  19. xtrabackup: innodb_data_home_dir = ./
  20. xtrabackup: innodb_data_file_path = ibdata1:10M:autoextend
  21. xtrabackup: innodb_log_group_home_dir = ./
  22. xtrabackup: innodb_log_files_in_group =
  23. xtrabackup: innodb_log_file_size =
  24. xtrabackup: Starting InnoDB instance for recovery.
  25. xtrabackup: Using bytes for buffer pool (set by --use-memory parameter)
  26. InnoDB: Using atomics to ref count buffer pool pages
  27. InnoDB: The InnoDB memory heap is disabled
  28. InnoDB: Mutexes and rw_locks use GCC atomic builtins
  29. InnoDB: Memory barrier is not used
  30. InnoDB: Compressed tables use zlib 1.2.
  31. InnoDB: Not using CPU crc32 instructions
  32. InnoDB: Initializing buffer pool, size = .0M
  33. InnoDB: Completed initialization of buffer pool
  34. InnoDB: Highest supported file format is Barracuda.
  35. InnoDB: Log scan progressed past the checkpoint lsn
  36. InnoDB: Database was not shutdown normally!
  37. InnoDB: Starting crash recovery.
  38. InnoDB: Reading tablespace information from the .ibd files...
  39. InnoDB: Restoring possible half-written data pages
  40. InnoDB: from the doublewrite buffer...
  41. InnoDB: Doing recovery: scanned up to log sequence number (%)
  42. InnoDB: Starting an apply batch of log records to the database...
  43. InnoDB: Progress in percent:
  44. InnoDB: Apply batch completed
  45. InnoDB: rollback segment(s) are active.
  46. InnoDB: Waiting for purge to start
  47. InnoDB: 5.6. started; log sequence number
  48. xtrabackup: Last MySQL binlog file position , file name mysql-bin. ()
  49.  
  50. xtrabackup: starting shutdown with innodb_fast_shutdown =
  51. InnoDB: FTS optimize thread exiting.
  52. InnoDB: Starting shutdown...
  53. InnoDB: Shutdown completed; log sequence number
  54. xtrabackup: using the following InnoDB configuration for recovery:
  55. xtrabackup: innodb_data_home_dir = ./
  56. xtrabackup: innodb_data_file_path = ibdata1:10M:autoextend
  57. xtrabackup: innodb_log_group_home_dir = ./
  58. xtrabackup: innodb_log_files_in_group =
  59. xtrabackup: innodb_log_file_size =
  60. InnoDB: Using atomics to ref count buffer pool pages
  61. InnoDB: The InnoDB memory heap is disabled
  62. InnoDB: Mutexes and rw_locks use GCC atomic builtins
  63. InnoDB: Memory barrier is not used
  64. InnoDB: Compressed tables use zlib 1.2.
  65. InnoDB: Not using CPU crc32 instructions
  66. InnoDB: Initializing buffer pool, size = .0M
  67. InnoDB: Completed initialization of buffer pool
  68. InnoDB: Setting log file ./ib_logfile101 size to MB
  69. InnoDB: Setting log file ./ib_logfile1 size to MB
  70. InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
  71. InnoDB: New log files created, LSN=
  72. InnoDB: Highest supported file format is Barracuda.
  73. InnoDB: rollback segment(s) are active.
  74. InnoDB: Waiting for purge to start
  75. InnoDB: 5.6. started; log sequence number
  76. xtrabackup: starting shutdown with innodb_fast_shutdown =
  77. InnoDB: FTS optimize thread exiting.
  78. InnoDB: Starting shutdown...
  79. InnoDB: Shutdown completed; log sequence number
  80. :: completed OK!
  81. [root@localhost ~]#
3.3 恢复 --copy-back
直接将上面prepare好的所有文件,复制到mysqld的datadir目录(会读取my.cnf中的配置信息)。
--copy--back的注意事项:
1> datadir必须是空的,或者使用--force-non-empty-directories选项;
2> mysqld必须关闭,如果是--import部分恢复,则不能关闭;
3> --copy-back完成之后,需要修改datadir目录下的文件权限: chown -R mysql:mysql /var/lib/mysql
[root@localhost ~]# mysqladmin -uroot -pxxx shutdown (关闭mysqld)
[root@localhost ~]# cd /var/lib/mysql
[root@localhost mysql]# ls
aazj         ib_logfile1         mysql-bin.000003  mysql-bin.000008  mysql-bin.000013  performance_schema
auto.cnf     localhost-slow.log  mysql-bin.000004  mysql-bin.000009  mysql-bin.000014  t
general.log  mysql               mysql-bin.000005  mysql-bin.000010  mysql-bin.000015  xtrabackup_binlog_pos_innodb
ibdata1      mysql-bin.000001    mysql-bin.000006  mysql-bin.000011  mysql-bin.000016  xtrabackup_info
ib_logfile0  mysql-bin.000002    mysql-bin.000007  mysql-bin.000012  mysql-bin.index
[root@localhost mysql]# mv * /backup/xtrabackup/  (进行清空)
[root@localhost mysql]# ls
[root@localhost mysql]# innobackupex --copy-back /backup/xtrabackup/full/2015-11-05_22-38-55/ --user=bkpuser --password=digdeep
  1. [root@localhost mysql]# innobackupex --copy-back /backup/xtrabackup/full/2015-11-05_22-38-55/ --user=bkpuser --password=digdeep
  2. :: innobackupex: Starting the copy-back operation
  3.  
  4. IMPORTANT: Please check that the copy-back run completes successfully.
  5. At the end of a successful copy-back run innobackupex
  6. prints "completed OK!".
  7.  
  8. innobackupex version 2.3. based on MySQL server 5.6. Linux (i686) (revision id: 306a2e0)
  9. :: [] Copying ib_logfile0 to /var/lib/mysql/ib_logfile0
  10. :: [] ...done
  11. :: [] Copying ib_logfile1 to /var/lib/mysql/ib_logfile1
  12. :: [] ...done
  13. :: [] Copying ibdata1 to /var/lib/mysql/ibdata1
  14. :: [] ...done
  15. :: [] Copying ./xtrabackup_info to /var/lib/mysql/xtrabackup_info
  16. :: [] ...done
  17. :: [] Copying ./mysql/slave_master_info.ibd to /var/lib/mysql/mysql/slave_master_info.ibd
  18. :: [] ...done
  19. [... ...]
  20. :: [] Copying ./t/db.opt to /var/lib/mysql/t/db.opt
  21. :: [] ...done
  22. :: [] Copying ./t/t.frm to /var/lib/mysql/t/t.frm
  23. :: [] ...done
  24. :: completed OK!
  25. [root@localhost mysql]# pwd
  26. /var/lib/mysql
  27. [root@localhost mysql]# ls
  28. aazj ibdata1 ib_logfile0 ib_logfile1 mysql performance_schema t xtrabackup_binlog_pos_innodb xtrabackup_info
可以看到恢复之后,没有 binlog 文件盒index文件
启动myqld之前需要修改权限:
  1. [root@localhost mysql]# ls -l
  2. total
  3. drwx------ root root Nov : aazj
  4. -rw-rw---- mysql mysql Nov : general.log
  5. -rw-r----- root root Nov : ibdata1
  6. -rw-r----- root root Nov : ib_logfile0
  7. -rw-r----- root root Nov : ib_logfile1
  8. -rw-rw---- mysql mysql Nov : localhost-slow.log
  9. drwx------ root root Nov : mysql
  10. -rw-rw---- mysql mysql Nov : mysql-bin.index
  11. drwx------ root root Nov : performance_schema
  12. drwx------ root root Nov : t
  13. -rw-r----- root root Nov : xtrabackup_binlog_pos_innodb
  14. -rw-r----- root root Nov : xtrabackup_info
  15. [root@localhost mysql]# chown -R mysql:mysql /var/lib/mysql
  16. [root@localhost mysql]# ls -l
  17. total
  18. drwx------ mysql mysql Nov : aazj
  19. -rw-rw---- mysql mysql Nov : general.log
  20. -rw-r----- mysql mysql Nov : ibdata1
  21. -rw-r----- mysql mysql Nov : ib_logfile0
  22. -rw-r----- mysql mysql Nov : ib_logfile1
  23. -rw-rw---- mysql mysql Nov : localhost-slow.log
  24. drwx------ mysql mysql Nov : mysql
  25. -rw-rw---- mysql mysql Nov : mysql-bin.index
  26. drwx------ mysql mysql Nov : performance_schema
  27. drwx------ mysql mysql Nov : t
  28. -rw-r----- mysql mysql Nov : xtrabackup_binlog_pos_innodb
  29. -rw-r----- mysql mysql Nov : xtrabackup_info
不然启动会在error.log中报错:
2015-11-06 11:13:55 3542 [ERROR] InnoDB: ./ibdata1 can't be opened in read-write mode
2015-11-06 11:13:55 3542 [ERROR] InnoDB: The system tablespace must be writable!
2015-11-06 11:13:55 3542 [ERROR] Plugin 'InnoDB' init function returned error.
2015-11-06 11:13:55 3542 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2015-11-06 11:13:55 3542 [ERROR] Unknown/unsupported storage engine: InnoDB
2015-11-06 11:13:55 3542 [ERROR] Aborting
 
启动成功之后,datadir目录下各种文件都产生了:
[root@localhost mysql]# pwd
/var/lib/mysql
[root@localhost mysql]# ls
aazj      general.log  ib_logfile0  localhost-slow.log  mysql-bin.000001  performance_schema  xtrabackup_binlog_pos_innodb
auto.cnf  ibdata1      ib_logfile1  mysql               mysql-bin.index   t                   xtrabackup_info
3.4 innobackupex 增量备份
增量备份之前,必须建立一个全备,第一次增量备份是在全备的基础之上,第二次增量备份是在第一次增量备份的基础之上的,一次类推
全备:
[root@localhost mysql]# innobackupex --user=bkpuser --password=digdeep /backup/xtrabackup/full
  1. [root@localhost mysql]# innobackupex --user=bkpuser --password=digdeep /backup/xtrabackup/full
  2. 第一次增量备份:
  3. --incremental /backup/xtrabackup/incr1/ 指定增量备份的位置;
  4. --incremental-basedir=指定上一次的全备或者增量备份:
  5. [root@localhost mysql]# innobackupex --incremental /backup/xtrabackup/incr1/ --incremental-basedir=/backup/xtrabackup/full/2015-11-06_11-29-51/ --user=bkpuser --password=digdeep
  6. :: innobackupex: Starting the backup operation
  7.  
  8. IMPORTANT: Please check that the backup run completes successfully.
  9. At the end of a successful backup run innobackupex
  10. prints "completed OK!".
  11.  
  12. :: version_check Connecting to MySQL server with DSN 'dbi:mysql:;mysql_read_default_group=xtrabackup;mysql_socket=/tmp/mysql.sock' as 'bkpuser' (using password: YES).
  13. :: version_check Connected to MySQL server
  14. :: version_check Executing a version check against the server...
  15. :: version_check Done.
  16. :: Connecting to MySQL server host: localhost, user: bkpuser, password: set, port: , socket: /tmp/mysql.sock
  17. Using server version 5.6.-log
  18. innobackupex version 2.3. based on MySQL server 5.6. Linux (i686) (revision id: 306a2e0)
  19. incremental backup from is enabled.
  20. xtrabackup: uses posix_fadvise().
  21. xtrabackup: cd to /var/lib/mysql
  22. xtrabackup: open files limit requested , set to
  23. xtrabackup: using the following InnoDB configuration:
  24. xtrabackup: innodb_data_home_dir = ./
  25. xtrabackup: innodb_data_file_path = ibdata1:12M:autoextend
  26. xtrabackup: innodb_log_group_home_dir = ./
  27. xtrabackup: innodb_log_files_in_group =
  28. xtrabackup: innodb_log_file_size =
  29. :: >> log scanned up to ()
  30. xtrabackup: Generating a list of tablespaces
  31. xtrabackup: using the full scan for incremental backup
  32. :: [] Copying ./ibdata1 to /backup/xtrabackup/incr1//--06_11--/ibdata1.delta
  33. :: >> log scanned up to ()
  34. :: [] ...done
  35. :: >> log scanned up to ()
  36. :: [] Copying ./mysql/slave_master_info.ibd to /backup/xtrabackup/incr1//--06_11--/mysql/slave_master_info.ibd.delta
  37. :: [] ...done
  38. :: >> log scanned up to ()
  39. [... ...]
  40. :: [] Copying ./aazj/Configuration.ibd to /backup/xtrabackup/incr1//--06_11--/aazj/Configuration.ibd.delta
  41. :: [] ...done
  42. :: [] Copying ./aazj/lx_test.ibd to /backup/xtrabackup/incr1//--06_11--/aazj/lx_test.ibd.delta
  43. :: >> log scanned up to ()
  44. :: [] ...done
  45. :: >> log scanned up to ()
  46. :: [] Copying ./aazj/Users.ibd to /backup/xtrabackup/incr1//--06_11--/aazj/Users.ibd.delta
  47. :: [] ...done
  48. [... ...]
  49. :: [] Copying ./aazj/tttt.ibd to /backup/xtrabackup/incr1//--06_11--/aazj/tttt.ibd.delta
  50. :: [] ...done
  51. :: >> log scanned up to ()
  52. :: [] Copying ./aazj/uu_test.ibd to /backup/xtrabackup/incr1//--06_11--/aazj/uu_test.ibd.delta
  53. [... ...]
  54. :: [] Copying ./t/t.ibd to /backup/xtrabackup/incr1//--06_11--/t/t.ibd.delta
  55. :: [] ...done
  56. :: >> log scanned up to ()
  57. Executing FLUSH NO_WRITE_TO_BINLOG TABLES...
  58. :: Executing FLUSH TABLES WITH READ LOCK...
  59. :: Starting to backup non-InnoDB tables and files
  60. :: [] Copying ./mysql/columns_priv.frm to /backup/xtrabackup/incr1//--06_11--/mysql/columns_priv.frm
  61. :: [] ...done
  62. [... ...]
  63. :: [] Copying ./t/t.frm to /backup/xtrabackup/incr1//--06_11--/t/t.frm
  64. :: [] ...done
  65. :: Finished backing up non-InnoDB tables and files
  66. :: [] Writing xtrabackup_binlog_info
  67. :: [] ...done
  68. :: Executing FLUSH NO_WRITE_TO_BINLOG ENGINE LOGS...
  69. xtrabackup: The latest check point (for incremental): '732501432'
  70. xtrabackup: Stopping log copying thread.
  71. . :: >> log scanned up to ()
  72.  
  73. :: Executing UNLOCK TABLES
  74. :: All tables unlocked
  75. :: Backup created in directory '/backup/xtrabackup/incr1//2015-11-06_11-33-16'
  76. MySQL binlog position: filename 'mysql-bin.000001', position '157893'
  77. :: [] Writing backup-my.cnf
  78. :: [] ...done
  79. :: [] Writing xtrabackup_info
  80. :: [] ...done
  81. xtrabackup: Transaction log of lsn () to () was copied.
  82. :: completed OK!
  83. [root@localhost mysql]#
第二次增量备份:
[root@localhost mysql]# innobackupex --incremental /backup/xtrabackup/incr2 --incremental-basedir=/backup/xtrabackup/incr1/2015-11-06_11-33-16/ --user=bkpuser --password=digdeep
  1. [root@localhost mysql]# innobackupex --incremental /backup/xtrabackup/incr2 --incremental-basedir=/backup/xtrabackup/incr1/2015-11-06_11-33-16/ --user=bkpuser --password=digdeep
  2. :: innobackupex: Starting the backup operation
  3.  
  4. IMPORTANT: Please check that the backup run completes successfully.
  5. At the end of a successful backup run innobackupex
  6. prints "completed OK!".
  7.  
  8. :: version_check Connecting to MySQL server with DSN 'dbi:mysql:;mysql_read_default_group=xtrabackup;mysql_socket=/tmp/mysql.sock' as 'bkpuser' (using password: YES).
  9. :: version_check Connected to MySQL server
  10. :: version_check Executing a version check against the server...
  11. :: version_check Done.
  12. :: Connecting to MySQL server host: localhost, user: bkpuser, password: set, port: , socket: /tmp/mysql.sock
  13. Using server version 5.6.-log
  14. innobackupex version 2.3. based on MySQL server 5.6. Linux (i686) (revision id: 306a2e0)
  15. incremental backup from is enabled.
  16. xtrabackup: uses posix_fadvise().
  17. xtrabackup: cd to /var/lib/mysql
  18. xtrabackup: open files limit requested , set to
  19. xtrabackup: using the following InnoDB configuration:
  20. xtrabackup: innodb_data_home_dir = ./
  21. xtrabackup: innodb_data_file_path = ibdata1:12M:autoextend
  22. xtrabackup: innodb_log_group_home_dir = ./
  23. xtrabackup: innodb_log_files_in_group =
  24. xtrabackup: innodb_log_file_size =
  25. :: >> log scanned up to ()
  26. xtrabackup: Generating a list of tablespaces
  27. :: [] Copying ./ibdata1 to /backup/xtrabackup/incr2/--06_11--/ibdata1.delta
  28. :: [] ...done
  29. :: >> log scanned up to ()
  30. :: [] Copying ./mysql/slave_master_info.ibd to /backup/xtrabackup/incr2/--06_11--/mysql/slave_master_info.ibd.delta
  31. :: [] ...done
  32. :: >> log scanned up to ()
  33. :: [] Copying ./mysql/innodb_index_stats.ibd to /backup/xtrabackup/incr2/--06_11--/mysql/innodb_index_stats.ibd.delta
  34. :: [] ...done
  35. :: [] Copying ./mysql/slave_relay_log_info.ibd to /backup/xtrabackup/incr2/--06_11--/mysql/slave_relay_log_info.ibd.delta
  36. :: [] ...done
  37. :: >> log scanned up to ()
  38. :: [] Copying ./mysql/slave_worker_info.ibd to /backup/xtrabackup/incr2/--06_11--/mysql/slave_worker_info.ibd.delta
  39. :: [] ...done
  40. :: [] Copying ./mysql/innodb_table_stats.ibd to /backup/xtrabackup/incr2/--06_11--/mysql/innodb_table_stats.ibd.delta
  41. :: [] ...done
  42. :: >> log scanned up to ()
  43. :: [] Copying ./aazj/u_test.ibd to /backup/xtrabackup/incr2/--06_11--/aazj/u_test.ibd.delta
  44. :: [] ...done
  45. [... ...]
  46. :: [] Copying ./t/t.frm to /backup/xtrabackup/incr2/--06_11--/t/t.frm
  47. :: [] ...done
  48. :: Finished backing up non-InnoDB tables and files
  49. :: [] Writing xtrabackup_binlog_info
  50. :: [] ...done
  51. :: Executing FLUSH NO_WRITE_TO_BINLOG ENGINE LOGS...
  52. xtrabackup: The latest check point (for incremental): '732777035'
  53. xtrabackup: Stopping log copying thread.
  54. . :: >> log scanned up to ()
  55.  
  56. :: Executing UNLOCK TABLES
  57. :: All tables unlocked
  58. :: Backup created in directory '/backup/xtrabackup/incr2/2015-11-06_11-43-22'
  59. MySQL binlog position: filename 'mysql-bin.000001', position '254400'
  60. :: [] Writing backup-my.cnf
  61. :: [] ...done
  62. :: [] Writing xtrabackup_info
  63. :: [] ...done
  64. xtrabackup: Transaction log of lsn () to () was copied.
  65. :: completed OK!
  66. [root@localhost mysql]#
3.5 innobackupex 增量备份的恢复
1> 应用全备的redo log:
[root@localhost ~]# innobackupex --apply-log --redo-only /backup/xtrabackup/full/2015-11-06_11-29-51/ --user=bkpuser --password=digdeep
  1. [root@localhost ~]# innobackupex --apply-log --redo-only /backup/xtrabackup/full/2015-11-06_11-29-51/ --user=bkpuser --password=digdeep
  2. :: innobackupex: Starting the apply-log operation
  3.  
  4. IMPORTANT: Please check that the apply-log run completes successfully.
  5. At the end of a successful apply-log run innobackupex
  6. prints "completed OK!".
  7.  
  8. innobackupex version 2.3. based on MySQL server 5.6. Linux (i686) (revision id: 306a2e0)
  9. xtrabackup: cd to /backup/xtrabackup/full/--06_11--/
  10. xtrabackup: This target seems to be not prepared yet.
  11. xtrabackup: xtrabackup_logfile detected: size=, start_lsn=()
  12. xtrabackup: using the following InnoDB configuration for recovery:
  13. xtrabackup: innodb_data_home_dir = ./
  14. xtrabackup: innodb_data_file_path = ibdata1:10M:autoextend
  15. xtrabackup: innodb_log_group_home_dir = ./
  16. xtrabackup: innodb_log_files_in_group =
  17. xtrabackup: innodb_log_file_size =
  18. xtrabackup: using the following InnoDB configuration for recovery:
  19. xtrabackup: innodb_data_home_dir = ./
  20. xtrabackup: innodb_data_file_path = ibdata1:10M:autoextend
  21. xtrabackup: innodb_log_group_home_dir = ./
  22. xtrabackup: innodb_log_files_in_group =
  23. xtrabackup: innodb_log_file_size =
  24. xtrabackup: Starting InnoDB instance for recovery.
  25. xtrabackup: Using bytes for buffer pool (set by --use-memory parameter)
  26. InnoDB: Using atomics to ref count buffer pool pages
  27. InnoDB: The InnoDB memory heap is disabled
  28. InnoDB: Mutexes and rw_locks use GCC atomic builtins
  29. InnoDB: Memory barrier is not used
  30. InnoDB: Compressed tables use zlib 1.2.
  31. InnoDB: Not using CPU crc32 instructions
  32. InnoDB: Initializing buffer pool, size = .0M
  33. InnoDB: Completed initialization of buffer pool
  34. InnoDB: Highest supported file format is Barracuda.
  35. InnoDB: The log sequence numbers and in ibdata files do not match the log sequence number in the ib_logfiles!
  36. InnoDB: Database was not shutdown normally!
  37. InnoDB: Starting crash recovery.
  38. InnoDB: Reading tablespace information from the .ibd files...
  39. InnoDB: Restoring possible half-written data pages
  40. InnoDB: from the doublewrite buffer...
  41. xtrabackup: Last MySQL binlog file position , file name mysql-bin.
  42.  
  43. xtrabackup: starting shutdown with innodb_fast_shutdown =
  44. InnoDB: Starting shutdown...
  45. InnoDB: Shutdown completed; log sequence number
  46. :: completed OK!
2> 应用第一次增量备份的redo log:
[root@localhost ~]# innobackupex --apply-log --redo-only /backup/xtrabackup/full/2015-11-06_11-29-51/ --incremental-dir=/backup/xtrabackup/incr1/2015-11-06_11-33-16/ --user=bkpuser --password=digdeep
  1. [root@localhost ~]# innobackupex --apply-log --redo-only /backup/xtrabackup/full/2015-11-06_11-29-51/ --incremental-dir=/backup/xtrabackup/incr1/2015-11-06_11-33-16/ --user=bkpuser --password=digdeep
  2. :: innobackupex: Starting the apply-log operation
  3.  
  4. IMPORTANT: Please check that the apply-log run completes successfully.
  5. At the end of a successful apply-log run innobackupex
  6. prints "completed OK!".
  7.  
  8. innobackupex version 2.3. based on MySQL server 5.6. Linux (i686) (revision id: 306a2e0)
  9. incremental backup from is enabled.
  10. xtrabackup: cd to /backup/xtrabackup/full/--06_11--/
  11. xtrabackup: This target seems to be already prepared with --apply-log-only.
  12. xtrabackup: xtrabackup_logfile detected: size=, start_lsn=()
  13. xtrabackup: using the following InnoDB configuration for recovery:
  14. xtrabackup: innodb_data_home_dir = ./
  15. xtrabackup: innodb_data_file_path = ibdata1:10M:autoextend
  16. xtrabackup: innodb_log_group_home_dir = /backup/xtrabackup/incr1/--06_11--/
  17. xtrabackup: innodb_log_files_in_group =
  18. xtrabackup: innodb_log_file_size =
  19. xtrabackup: Generating a list of tablespaces
  20. xtrabackup: page size for /backup/xtrabackup/incr1/--06_11--//ibdata1.delta is bytes
  21. Applying /backup/xtrabackup/incr1/--06_11--//ibdata1.delta to ./ibdata1...
  22. xtrabackup: page size for /backup/xtrabackup/incr1/--06_11--//mysql/innodb_index_stats.ibd.delta is bytes
  23. [... ...]
  24. xtrabackup: page size for /backup/xtrabackup/incr1/--06_11--//aazj/tttt.ibd.delta is bytes
  25. Applying /backup/xtrabackup/incr1/--06_11--//aazj/tttt.ibd.delta to ./aazj/tttt.ibd...
  26. xtrabackup: page size for /backup/xtrabackup/incr1/--06_11--//aazj/Users.ibd.delta is bytes
  27. Applying /backup/xtrabackup/incr1/--06_11--//aazj/Users.ibd.delta to ./aazj/Users.ibd...
  28. xtrabackup: page size for /backup/xtrabackup/incr1/--06_11--//aazj/Gis.ibd.delta is bytes
  29. Applying /backup/xtrabackup/incr1/--06_11--//aazj/Gis.ibd.delta to ./aazj/Gis.ibd...
  30. [... ...]
  31. xtrabackup: page size for /backup/xtrabackup/incr1/--06_11--//t/t.ibd.delta is bytes
  32. Applying /backup/xtrabackup/incr1/--06_11--//t/t.ibd.delta to ./t/t.ibd...
  33. xtrabackup: using the following InnoDB configuration for recovery:
  34. xtrabackup: innodb_data_home_dir = ./
  35. xtrabackup: innodb_data_file_path = ibdata1:10M:autoextend
  36. xtrabackup: innodb_log_group_home_dir = /backup/xtrabackup/incr1/--06_11--/
  37. xtrabackup: innodb_log_files_in_group =
  38. xtrabackup: innodb_log_file_size =
  39. xtrabackup: Starting InnoDB instance for recovery.
  40. xtrabackup: Using bytes for buffer pool (set by --use-memory parameter)
  41. InnoDB: Using atomics to ref count buffer pool pages
  42. InnoDB: The InnoDB memory heap is disabled
  43. InnoDB: Mutexes and rw_locks use GCC atomic builtins
  44. InnoDB: Memory barrier is not used
  45. InnoDB: Compressed tables use zlib 1.2.
  46. InnoDB: Not using CPU crc32 instructions
  47. InnoDB: Initializing buffer pool, size = .0M
  48. InnoDB: Completed initialization of buffer pool
  49. InnoDB: Highest supported file format is Barracuda.
  50. InnoDB: Log scan progressed past the checkpoint lsn
  51. InnoDB: Database was not shutdown normally!
  52. InnoDB: Starting crash recovery.
  53. InnoDB: Reading tablespace information from the .ibd files...
  54. InnoDB: Restoring possible half-written data pages
  55. InnoDB: from the doublewrite buffer...
  56. InnoDB: Doing recovery: scanned up to log sequence number (%)
  57. InnoDB: Starting an apply batch of log records to the database...
  58. InnoDB: Progress in percent:
  59. InnoDB: Apply batch completed
  60. xtrabackup: Last MySQL binlog file position , file name mysql-bin.
  61.  
  62. xtrabackup: starting shutdown with innodb_fast_shutdown =
  63. InnoDB: Starting shutdown...
  64. InnoDB: Shutdown completed; log sequence number
  65. :: [] Copying /backup/xtrabackup/incr1/--06_11--/mysql/columns_priv.frm to ./mysql/columns_priv.frm
  66. :: [] ...done
  67. :: [] Copying /backup/xtrabackup/incr1/--06_11--/mysql/user.MYI to ./mysql/user.MYI
  68. :: [] ...done
  69. :: [] Copying /backup/xtrabackup/incr1/--06_11--/mysql/general_log.frm to ./mysql/general_log.frm
  70. :: [] ...done
  71. [... ...]
  72. :: [] Copying /backup/xtrabackup/incr1/--06_11--/t/city.frm to ./t/city.frm
  73. :: [] ...done
  74. :: [] Copying /backup/xtrabackup/incr1/--06_11--/t/db.opt to ./t/db.opt
  75. :: [] ...done
  76. :: [] Copying /backup/xtrabackup/incr1/--06_11--/t/t.frm to ./t/t.frm
  77. :: [] ...done
  78. :: completed OK!
3> 应用第二次(最后一次)增量备份的redo log,并且回滚进行崩溃恢复过程(没有--redo-only选项):
[root@localhost ~]# innobackupex --apply-log /backup/xtrabackup/full/2015-11-06_11-29-51/ --incremental-dir=/backup/xtrabackup/incr2/2015-1  1-06_11-43-22/ --user=bkpuser --password=digdeep
  1. [root@localhost ~]# innobackupex --apply-log /backup/xtrabackup/full/2015-11-06_11-29-51/ --incremental-dir=/backup/xtrabackup/incr2/2015-1 1-06_11-43-22/ --user=bkpuser --password=digdeep
  2. :: innobackupex: Starting the apply-log operation
  3.  
  4. IMPORTANT: Please check that the apply-log run completes successfully.
  5. At the end of a successful apply-log run innobackupex
  6. prints "completed OK!".
  7.  
  8. innobackupex version 2.3. based on MySQL server 5.6. Linux (i686) (revision id: 306a2e0)
  9. incremental backup from is enabled.
  10. xtrabackup: cd to /backup/xtrabackup/full/--06_11--/
  11. xtrabackup: This target seems to be already prepared with --apply-log-only.
  12. xtrabackup: xtrabackup_logfile detected: size=, start_lsn=()
  13. xtrabackup: using the following InnoDB configuration for recovery:
  14. xtrabackup: innodb_data_home_dir = ./
  15. xtrabackup: innodb_data_file_path = ibdata1:10M:autoextend
  16. xtrabackup: innodb_log_group_home_dir = /backup/xtrabackup/incr2/--06_11--/
  17. xtrabackup: innodb_log_files_in_group =
  18. xtrabackup: innodb_log_file_size =
  19. xtrabackup: Generating a list of tablespaces
  20. xtrabackup: page size for /backup/xtrabackup/incr2/--06_11--//ibdata1.delta is bytes
  21. Applying /backup/xtrabackup/incr2/--06_11--//ibdata1.delta to ./ibdata1...
  22. xtrabackup: page size for /backup/xtrabackup/incr2/--06_11--//mysql/innodb_index_stats.ibd.delta is bytes
  23. Applying /backup/xtrabackup/incr2/--06_11--//mysql/innodb_index_stats.ibd.delta to ./mysql/innodb_index_stats.ibd...
  24. [... ...]
  25. Applying /backup/xtrabackup/incr2/--06_11--//t/city.ibd.delta to ./t/city.ibd...
  26. xtrabackup: page size for /backup/xtrabackup/incr2/--06_11--//t/t.ibd.delta is bytes
  27. Applying /backup/xtrabackup/incr2/--06_11--//t/t.ibd.delta to ./t/t.ibd...
  28. xtrabackup: using the following InnoDB configuration for recovery:
  29. xtrabackup: innodb_data_home_dir = ./
  30. xtrabackup: innodb_data_file_path = ibdata1:10M:autoextend
  31. xtrabackup: innodb_log_group_home_dir = /backup/xtrabackup/incr2/--06_11--/
  32. xtrabackup: innodb_log_files_in_group =
  33. xtrabackup: innodb_log_file_size =
  34. xtrabackup: Starting InnoDB instance for recovery.
  35. xtrabackup: Using bytes for buffer pool (set by --use-memory parameter)
  36. InnoDB: Using atomics to ref count buffer pool pages
  37. InnoDB: The InnoDB memory heap is disabled
  38. InnoDB: Mutexes and rw_locks use GCC atomic builtins
  39. InnoDB: Memory barrier is not used
  40. InnoDB: Compressed tables use zlib 1.2.
  41. InnoDB: Not using CPU crc32 instructions
  42. InnoDB: Initializing buffer pool, size = .0M
  43. InnoDB: Completed initialization of buffer pool
  44. InnoDB: Highest supported file format is Barracuda.
  45. InnoDB: Log scan progressed past the checkpoint lsn
  46. InnoDB: Database was not shutdown normally!
  47. InnoDB: Starting crash recovery.
  48. InnoDB: Reading tablespace information from the .ibd files...
  49. InnoDB: Restoring possible half-written data pages
  50. InnoDB: from the doublewrite buffer...
  51. InnoDB: Doing recovery: scanned up to log sequence number (%)
  52. InnoDB: Starting an apply batch of log records to the database...
  53. InnoDB: Progress in percent:
  54. InnoDB: Apply batch completed
  55. InnoDB: rollback segment(s) are active.
  56. InnoDB: Waiting for purge to start
  57. InnoDB: 5.6. started; log sequence number
  58. xtrabackup: Last MySQL binlog file position , file name mysql-bin.
  59.  
  60. xtrabackup: starting shutdown with innodb_fast_shutdown =
  61. InnoDB: FTS optimize thread exiting.
  62. InnoDB: Starting shutdown...
  63. InnoDB: Shutdown completed; log sequence number
  64. :: [] Copying /backup/xtrabackup/incr2/--06_11--/mysql/columns_priv.frm to ./mysql/columns_priv.frm
  65. :: [] ...done
  66. :: [] Copying /backup/xtrabackup/incr2/--06_11--/mysql/user.MYI to ./mysql/user.MYI
  67. :: [] ...done
  68. [... ...]
  69. :: [] Copying /backup/xtrabackup/incr2/--06_11--/t/db.opt to ./t/db.opt
  70. :: [] ...done
  71. :: [] Copying /backup/xtrabackup/incr2/--06_11--/t/t.frm to ./t/t.frm
  72. :: [] ...done
  73. xtrabackup: using the following InnoDB configuration for recovery:
  74. xtrabackup: innodb_data_home_dir = ./
  75. xtrabackup: innodb_data_file_path = ibdata1:10M:autoextend
  76. xtrabackup: innodb_log_group_home_dir = /backup/xtrabackup/incr2/--06_11--/
  77. xtrabackup: innodb_log_files_in_group =
  78. xtrabackup: innodb_log_file_size =
  79. InnoDB: Using atomics to ref count buffer pool pages
  80. InnoDB: The InnoDB memory heap is disabled
  81. InnoDB: Mutexes and rw_locks use GCC atomic builtins
  82. InnoDB: Memory barrier is not used
  83. InnoDB: Compressed tables use zlib 1.2.
  84. InnoDB: Not using CPU crc32 instructions
  85. InnoDB: Initializing buffer pool, size = .0M
  86. InnoDB: Completed initialization of buffer pool
  87. InnoDB: Setting log file /backup/xtrabackup/incr2/--06_11--/ib_logfile101 size to MB
  88. InnoDB: Setting log file /backup/xtrabackup/incr2/--06_11--/ib_logfile1 size to MB
  89. InnoDB: Renaming log file /backup/xtrabackup/incr2/--06_11--/ib_logfile101 to /backup/xtrabackup/incr2/--06_11--/ib_logfile0
  90. InnoDB: New log files created, LSN=
  91. InnoDB: Highest supported file format is Barracuda.
  92. InnoDB: rollback segment(s) are active.
  93. InnoDB: Waiting for purge to start
  94. InnoDB: 5.6. started; log sequence number
  95. xtrabackup: starting shutdown with innodb_fast_shutdown =
  96. InnoDB: FTS optimize thread exiting.
  97. InnoDB: Starting shutdown...
  98. InnoDB: Shutdown completed; log sequence number
  99. :: completed OK!
然后 --copy-back:
先关闭mysqld: mysqladmin -uroot -pxxx shutdown
[root@localhost mysql]# innobackupex --copy-back /backup/xtrabackup/full/2015-11-06_11-29-51/ --user=bkpuser --password=digdeep
  1. [root@localhost mysql]# innobackupex --copy-back /backup/xtrabackup/full/2015-11-06_11-29-51/ --user=bkpuser --password=digdeep
  2. :: innobackupex: Starting the copy-back operation
  3.  
  4. IMPORTANT: Please check that the copy-back run completes successfully.
  5. At the end of a successful copy-back run innobackupex
  6. prints "completed OK!".
  7.  
  8. innobackupex version 2.3. based on MySQL server 5.6. Linux (i686) (revision id: 306a2e0)
  9. :: [] Copying ibdata1 to /var/lib/mysql/ibdata1
  10. :: [] ...done
  11. :: [] Copying ./xtrabackup_info to /var/lib/mysql/xtrabackup_info
  12. :: [] ...done
  13. [... ...]
  14. :: [] ...done
  15. :: [] Copying ./t/db.opt to /var/lib/mysql/t/db.opt
  16. :: [] ...done
  17. :: [] Copying ./t/t.frm to /var/lib/mysql/t/t.frm
  18. :: [] ...done
  19. :: completed OK!
修改权限:
chown -R mysql:mysql /var/lib/mysql
启动:mysqld_safe --user=mysql &
最后验证还原成功。
4. 部分备份
需要启用 innodb_file_per_table,5.6默认启用。另外在还原时,prepare之后,并不能直接 --copy-back,而只能一个表一个表的import来还原。
[root@localhost xtrabackup]# innobackupex --databases t /backup/xtrabackup/ --user=bkpuser --password=digdeep
  1. [root@localhost xtrabackup]# innobackupex --databases t /backup/xtrabackup/ --user=bkpuser --password=digdeep
  2. :: innobackupex: Starting the backup operation
  3.  
  4. IMPORTANT: Please check that the backup run completes successfully.
  5. At the end of a successful backup run innobackupex
  6. prints "completed OK!".
  7.  
  8. :: version_check Connecting to MySQL server with DSN 'dbi:mysql:;mysql_read_default_group=xtrabackup;mysql_socket=/tmp/mysql. sock' as 'bkpuser' (using password: YES).
  9. :: version_check Connected to MySQL server
  10. :: version_check Executing a version check against the server...
  11. :: version_check Done.
  12. :: Connecting to MySQL server host: localhost, user: bkpuser, password: set, port: , socket: /tmp/mysql.sock
  13. Using server version 5.6.-log
  14. innobackupex version 2.3. based on MySQL server 5.6. Linux (i686) (revision id: 306a2e0)
  15. xtrabackup: uses posix_fadvise().
  16. xtrabackup: cd to /var/lib/mysql
  17. xtrabackup: open files limit requested , set to
  18. xtrabackup: using the following InnoDB configuration:
  19. xtrabackup: innodb_data_home_dir = ./
  20. xtrabackup: innodb_data_file_path = ibdata1:12M:autoextend
  21. xtrabackup: innodb_log_group_home_dir = ./
  22. xtrabackup: innodb_log_files_in_group =
  23. xtrabackup: innodb_log_file_size =
  24. :: >> log scanned up to ()
  25. xtrabackup: Generating a list of tablespaces
  26. :: [] Copying ./ibdata1 to /backup/xtrabackup//--06_15--/ibdata1
  27. :: >> log scanned up to ()
  28. :: >> log scanned up to ()
  29. :: [] ...done
  30. :: [] Copying ./t/city.ibd to /backup/xtrabackup//--06_15--/t/city.ibd
  31. :: [] ...done
  32. :: [] Copying ./t/t.ibd to /backup/xtrabackup//--06_15--/t/t.ibd
  33. :: [] ...done
  34. :: >> log scanned up to ()
  35. Executing FLUSH NO_WRITE_TO_BINLOG TABLES...
  36. :: Executing FLUSH TABLES WITH READ LOCK...
  37. :: Starting to backup non-InnoDB tables and files
  38. :: [] Skipping ./mysql/slave_master_info.ibd.
  39. :: [] Skipping ./mysql/columns_priv.frm.
  40. [... ...]
  41. :: [] Skipping ./aazj/model_buyers_credit.ibd.
  42. :: [] Skipping ./aazj/Users.frm.
  43. :: [] Skipping ./aazj/model_recruiting_program.ibd.
  44. :: [] Skipping ./aazj/model_model.ibd.
  45. :: [] Skipping ./aazj/Customer.frm.
  46. :: [] Skipping ./performance_schema/events_waits_summary_by_host_by_event_name.frm.
  47. [... ...]
  48. :: [] Skipping ./performance_schema/events_statements_summary_by_account_by_event_name.frm.
  49. :: [] Copying ./t/city.frm to /backup/xtrabackup//--06_15--/t/city.frm
  50. :: [] ...done
  51. :: [] Copying ./t/db.opt to /backup/xtrabackup//--06_15--/t/db.opt
  52. :: [] ...done
  53. :: [] Copying ./t/t.frm to /backup/xtrabackup//--06_15--/t/t.frm
  54. :: [] ...done
  55. :: Finished backing up non-InnoDB tables and files
  56. :: [] Writing xtrabackup_binlog_info
  57. :: [] ...done
  58. :: Executing FLUSH NO_WRITE_TO_BINLOG ENGINE LOGS...
  59. xtrabackup: The latest check point (for incremental): '732817942'
  60. xtrabackup: Stopping log copying thread.
  61. . :: >> log scanned up to ()
  62.  
  63. :: Executing UNLOCK TABLES
  64. :: All tables unlocked
  65. :: Backup created in directory '/backup/xtrabackup//2015-11-06_15-39-34'
  66. MySQL binlog position: filename 'mysql-bin.000001', position '120'
  67. :: [] Writing backup-my.cnf
  68. :: [] ...done
  69. :: [] Writing xtrabackup_info
  70. :: [] ...done
  71. xtrabackup: Transaction log of lsn () to () was copied.
  72. :: completed OK!
数据库 t 中只有两个表:city, t 都被备份了。
下面我们来看如何还原:
4.1 部分prepare:
[root@localhost xtrabackup]# innobackupex --apply-log --export /backup/xtrabackup/2015-11-06_15-39-34/ --user=bkpuser --password=digdeep
  1. [root@localhost xtrabackup]# innobackupex --apply-log --export /backup/xtrabackup/2015-11-06_15-39-34/ --user=bkpuser --password=digdeep
  2. :: innobackupex: Starting the apply-log operation
  3.  
  4. IMPORTANT: Please check that the apply-log run completes successfully.
  5. At the end of a successful apply-log run innobackupex
  6. prints "completed OK!".
  7.  
  8. innobackupex version 2.3. based on MySQL server 5.6. Linux (i686) (revision id: 306a2e0)
  9. xtrabackup: auto-enabling --innodb-file-per-table due to the --export option
  10. xtrabackup: cd to /backup/xtrabackup/--06_15--/
  11. xtrabackup: This target seems to be not prepared yet.
  12. xtrabackup: xtrabackup_logfile detected: size=, start_lsn=()
  13. xtrabackup: using the following InnoDB configuration for recovery:
  14. xtrabackup: innodb_data_home_dir = ./
  15. xtrabackup: innodb_data_file_path = ibdata1:10M:autoextend
  16. xtrabackup: innodb_log_group_home_dir = ./
  17. xtrabackup: innodb_log_files_in_group =
  18. xtrabackup: innodb_log_file_size =
  19. xtrabackup: using the following InnoDB configuration for recovery:
  20. xtrabackup: innodb_data_home_dir = ./
  21. xtrabackup: innodb_data_file_path = ibdata1:10M:autoextend
  22. xtrabackup: innodb_log_group_home_dir = ./
  23. xtrabackup: innodb_log_files_in_group =
  24. xtrabackup: innodb_log_file_size =
  25. xtrabackup: Starting InnoDB instance for recovery.
  26. xtrabackup: Using bytes for buffer pool (set by --use-memory parameter)
  27. InnoDB: Using atomics to ref count buffer pool pages
  28. InnoDB: The InnoDB memory heap is disabled
  29. InnoDB: Mutexes and rw_locks use GCC atomic builtins
  30. InnoDB: Memory barrier is not used
  31. InnoDB: Compressed tables use zlib 1.2.
  32. InnoDB: Not using CPU crc32 instructions
  33. InnoDB: Initializing buffer pool, size = .0M
  34. InnoDB: Completed initialization of buffer pool
  35. InnoDB: Highest supported file format is Barracuda.
  36. InnoDB: The log sequence numbers and in ibdata files do not match the log sequence number in the ib_logfiles!
  37. InnoDB: Database was not shutdown normally!
  38. InnoDB: Starting crash recovery.
  39. InnoDB: Reading tablespace information from the .ibd files...
  40. InnoDB: Restoring possible half-written data pages
  41. InnoDB: from the doublewrite buffer...
  42. InnoDB: Table aazj/Accounting_journal in the InnoDB data dictionary has tablespace id , but tablespace with that id or name does not exi st. Have you deleted or moved .ibd files? This may also be a table created with CREATE TEMPORARY TABLE whose .ibd and .frm files MySQL auto matically removed, but the table still exists in the InnoDB internal data dictionary.
  43. InnoDB: It will be removed from the data dictionary.
  44. InnoDB: Please refer to
  45. InnoDB: http://dev.mysql.com/doc/refman/5.6/en/innodb-troubleshooting-datadict.html
  46. InnoDB: for how to resolve the issue.
  47. [... ...]
  48. InnoDB: Table mysql/slave_relay_log_info in the InnoDB data dictionary has tablespace id , but tablespace with that id or name does not ex ist. Have you deleted or moved .ibd files? This may also be a table created with CREATE TEMPORARY TABLE whose .ibd and .frm files MySQL aut omatically removed, but the table still exists in the InnoDB internal data dictionary.
  49. InnoDB: It will be removed from the data dictionary.
  50. InnoDB: Please refer to
  51. InnoDB: http://dev.mysql.com/doc/refman/5.6/en/innodb-troubleshooting-datadict.html
  52. InnoDB: for how to resolve the issue.
  53. InnoDB: Table mysql/slave_worker_info in the InnoDB data dictionary has tablespace id , but tablespace with that id or name does not exist . Have you deleted or moved .ibd files? This may also be a table created with CREATE TEMPORARY TABLE whose .ibd and .frm files MySQL automa tically removed, but the table still exists in the InnoDB internal data dictionary.
  54. InnoDB: It will be removed from the data dictionary.
  55. InnoDB: Please refer to
  56. InnoDB: http://dev.mysql.com/doc/refman/5.6/en/innodb-troubleshooting-datadict.html
  57. InnoDB: for how to resolve the issue.
  58. InnoDB: rollback segment(s) are active.
  59. InnoDB: Waiting for purge to start
  60. InnoDB: 5.6. started; log sequence number
  61. xtrabackup: export option is specified.
  62. xtrabackup: export metadata of table 't/city' to file `./t/city.exp` ( indexes)
  63. xtrabackup: name=PRIMARY, id.low=, page=
  64. xtrabackup: name=PK_CITY, id.low=, page=
  65. xtrabackup: export metadata of table 't/t' to file `./t/t.exp` ( indexes)
  66. xtrabackup: name=GEN_CLUST_INDEX, id.low=, page=
  67. xtrabackup: Last MySQL binlog file position , file name mysql-bin.
  68.  
  69. xtrabackup: starting shutdown with innodb_fast_shutdown =
  70. InnoDB: FTS optimize thread exiting.
  71. InnoDB: Starting shutdown...
  72. InnoDB: Shutdown completed; log sequence number
  73. xtrabackup: using the following InnoDB configuration for recovery:
  74. xtrabackup: innodb_data_home_dir = ./
  75. xtrabackup: innodb_data_file_path = ibdata1:10M:autoextend
  76. xtrabackup: innodb_log_group_home_dir = ./
  77. xtrabackup: innodb_log_files_in_group =
  78. xtrabackup: innodb_log_file_size =
  79. InnoDB: Using atomics to ref count buffer pool pages
  80. InnoDB: The InnoDB memory heap is disabled
  81. InnoDB: Mutexes and rw_locks use GCC atomic builtins
  82. InnoDB: Memory barrier is not used
  83. InnoDB: Compressed tables use zlib 1.2.
  84. InnoDB: Not using CPU crc32 instructions
  85. InnoDB: Initializing buffer pool, size = .0M
  86. InnoDB: Completed initialization of buffer pool
  87. InnoDB: Setting log file ./ib_logfile101 size to MB
  88. InnoDB: Setting log file ./ib_logfile1 size to MB
  89. InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
  90. InnoDB: New log files created, LSN=
  91. InnoDB: Highest supported file format is Barracuda.
  92. InnoDB: rollback segment(s) are active.
  93. InnoDB: Waiting for purge to start
  94. InnoDB: 5.6. started; log sequence number
  95. xtrabackup: starting shutdown with innodb_fast_shutdown =
  96. InnoDB: FTS optimize thread exiting.
  97. InnoDB: Starting shutdown...
  98. InnoDB: Shutdown completed; log sequence number
  99. :: completed OK!
4.2 下面我们将其 import 到一个新的数据库中:
(root@localhost)[t]mysql>create database partial;
(root@localhost)[t]mysql>use partial;
Database changed
(root@localhost)[partial]mysql>create table city like t.city;
(root@localhost)[partial]mysql>alter table partial.city discard tablespace;
然后将 city.exp 和 city.ibd 拷贝到 /var/lib/mysql/partial/ 目录下,并修改权限:
[root@localhost t]# cp city.exp city.ibd /var/lib/mysql/partial/
[root@localhost partial]# chown -R mysql:mysql /var/lib/mysql
然后 
(root@localhost)[aazj]mysql>alter table partial.city import tablespace;
Query OK, 0 rows affected, 1 warning (0.11 sec)
 
(root@localhost)[aazj]mysql>select count(*) from partial.city;
+----------+
| count(*) |
+----------+
|     3285 |
+----------+
1 row in set (0.01 sec)
 
可以看到import 成功了。部分恢复成功。
低于t表也同样操作就行了。
(root@localhost)[partial]mysql>select count(*) from t;
+----------+
| count(*) |
+----------+
|       11 |
+----------+
1 row in set (0.00 sec)
 
可以看到,这种部分备份/恢复,操作起来比较麻烦,步骤比较多,还需要一个表一个表的处理。对少数表处理还可以,如果很多表,就不方面了。
4.3 部分备份恢复之备份/恢复一个或者多个数据库:
1)备份:
[root@localhost mysql]# innobackupex --database="aazj t mysql information_schema performance_schema" /backup/xtrabackup/partial/ --user=pkpuser --password=digdeep
注意这里 --database = "aazj t mysql performance_schema" 表示指定备份的数据库;还可以增加其他数据库,但是必须使用引号。
2)恢复 prepare:
[root@localhost partial]# innobackupex --apply-log /backup/xtrabackup/partial/2015-11-11_15-22-56 --user=bkpuser --password=digdeep
然后 关闭 mysqld, 清空 datadir :
[root@localhost mysql]# pwd
/var/lib/mysql
[root@localhost mysql]# rm -rf *
3)copy-back:
[root@localhost partial]# innobackupex --copy-back /backup/xtrabackup/partial/2015-11-11_15-22-56 --user=bkpuser --password=digdeep
然后修改权限:chown -R mysql:mysql /var/lib/mysql
然后启动mysqld,发现数据库 t 被恢复出来了。这里也可以一次备份多个数据库,但是一定要带上 mysql 数据库,不然恢复出来时,没有了数据字典,select读不出数据:
Restoring Partial Backups:
Restoring should be done by restoring individual tables in the partial backup to the server.
It can also be done by copying back the prepared backup to a clean datadir (in that case, make sure to include the mysql database). System database can be created with: $ sudo mysql_install_db --user=mysql (摘自xtrabackup文档)
部分恢复一般需要 export, 然后 import. 比较麻烦,但是我们也可以在一个空的 datadir 目录直接 --copy-back,这样的话,那么在备份的时候一定要带上mysql数据库,当然最好带上所有的系统数据库,不然的话,需要使用命令:mysql_install_db --user=mysql --basedir=... 重建那些系统数据库。这就是为什么在部分备份时带上了:mysql performance_schema(information_schema是系统视图,不需要带上,当然带上也是可以的)
4)如果你不想带上 performance_schema(mysql是一定要带上的),那么就必须使用: mysql_install_db --user=mysql --basedir=/usr/local/mysql 来重新生成系统数据库mysql 和 performance_schema。那么此时在 --copy-back之前,必须先删除刚才生成的 和 我们要 --copy-back 重复的文件:
[root@localhost mysql]# rm ibdata1 ib_logfile0 ib_logfile1
[root@localhost mysql]# rm -rf mysql
另外 --copy-back 时要带上参数: --force-non-empty-directories
innobackupex --copy-back --force-non-empty-directories /backup/xtrabackup/partial/2015-11-11_16-17-11/ --user=pkpuser --password=digdeep
因为 datadir 目录非空,所以需要带上该参数:
 --force-non-empty-directories
                      This option, when specified, makes --copy-back or
                      --move-back transfer files to non-empty directories. Note
                      that no existing files will be overwritten. If
                      --copy-back or --nove-back has to copy a file from the
                      backup directory which already exists in the destination
                      directory, it will still fail with an error.
即使带上了该参数,如果还存在重名的文件,还是会报错,需要先删除datadir中的重名文件。
 
5. point-in-time 恢复
利用全备、增量备份最多只能恢复到全备完成时的那一刻,或者增量备份完成时的那一刻的数据。备份之后产生的数据,我们需要结合binlog,来恢复。我们可以从binlog中获得innobackupex最后一次备份完成时的position,它之后的所有的sql,应用完,这些sql,就能将数据库恢复到最新的状态,或者我们想要的某个时间的状态。
1> 先来一个全备:
[root@localhost xtrabackup]# innobackupex /backup/xtrabackup/full --user=bkpuser --password=digdeep
2> 再来一个增量:
将t表数据删除一行:delete from t where i=11;
[root@localhost xtrabackup]# innobackupex --incremental /backup/xtrabackup/incr1/ --incremental-basedir=/backup/xtrabackup/full/2015-11-06_16-26-08 --user=bkpuser --password=digdeep
3> 再来一个增量:
将t表数据删除一行:delete from t where i=10;
[root@localhost xtrabackup]# innobackupex --incremental /backup/xtrabackup/incr2/ --incremental-basedir=/backup/xtrabackup/incr1/2015-11-06_16-31-13/ --user=bkpuser --password=digdeep
4> 备份完成之后,我们再来操作 t 表:
(root@localhost)[t]mysql>delete from t where i>3;
此时的状态:
(root@localhost)[t]mysql>show binary logs;
+------------------+-----------+
| Log_name         | File_size |
+------------------+-----------+
| mysql-bin.000001 |       927 |
| mysql-bin.000002 |       688 |
+------------------+-----------+
2 rows in set (0.00 sec)
 
(root@localhost)[t]mysql>show master status;
+------------------+----------+--------------+------------------+-------------------+
 | File                       | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000002 |      688 |              |                  |                   |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
 
假设此时数据库表数据所在的磁盘发生故障,但是 binlog 文件是好的。那么此时,我们就可以使用上面的全备、增量备份、还有binlog文件一起来将数据库恢复到磁盘发生故障那一刻的最新状态来。
5> 首先从全备、增量备份得到最后一次备份完成时的数据:
1)应用全备的redo log:
[root@localhost xtrabackup]# innobackupex --apply-log --redo-only /backup/xtrabackup/full/2015-11-06_16-26-08 --user=bkpuser --password=digdeep
2)应用第一次增量备份的redo log:
[root@localhost xtrabackup]# innobackupex --apply-log --redo-only /backup/xtrabackup/full/2015-11-06_16-26-08 --incremental-dir=/backup/xtr  abackup/incr1/2015-11-06_16-31-13/ --user=bkpuser --password=digdeep
3)应用第二次增量备份的 redo log,并且仅限回滚(去掉 --redo-only选项):
[root@localhost xtrabackup]# innobackupex --apply-log /backup/xtrabackup/full/2015-11-06_16-26-08 --incremental-dir=/backup/xtrabackup/incr2/2015-11-06_16-33-57/ --user=bkpuser --password=digdeep
此时已经恢复到了最后一次备份完成时的状态了。
我们看一下最后一次增量备份时的 xtrabackup_binlog_info 文件信息:
[root@localhost xtrabackup]# cat incr2/2015-11-06_16-33-57/xtrabackup_binlog_info
mysql-bin.000002        482
可以看到对应的binlog postion为:mysql-bin.000002        482
而崩溃那一刻的binlog postion为: mysql-bin.000002      688
 
所以我们需要应用 mysql-bin.000002 文件的 482 到 688之间的sql:
4)先 --copy-back
[root@localhost mysql]# innobackupex --copy-back /backup/xtrabackup/full/2015-11-06_16-26-08 --user=bkpuser --password=digdeep
修改权限:
[root@localhost ~]# chown -R mysql:mysql /var/lib/mysql
启动msyqld:  mysqld_safe --user=mysql &
然后验证,t 表的数据,应该有i<10 & i>3 的数据:
(root@localhost)[t]mysql>select * from t;
+------+
| i    |
+------+
|    1 |
|    2 |
|    3 |
|    4 |
|    5 |
|    6 |
|    7 |
|    8 |
|    9 |
+------+
9 rows in set (0.00 sec)
如我们所期待的结果一样。说明到此时,前面的操作完全是正确的。
5)应用 mysql-bin.000002 文件的 482 到 688之间的sql
[root@localhost mysql]#  mysqlbinlog /backup/xtrabackup/mysql-bin.000002 --start-position=482 > bin.sql
(root@localhost)[(none)]mysql>source /var/lib/mysql/bin.sql
然后在查看 t 表数据:
(root@localhost)[t]mysql>select * from t;
+------+
| i    |
+------+
|    1 |
|    2 |
|    3 |
+------+
3 rows in set (0.00 sec)
一切完美完成,数据库被我们回复到了最新的状态。
6. innobackupex 选项优化/最佳实践
6.1 优化FTWRL锁:
在备份非innodb数据库时,会使用:flush tables with read lock 全局锁锁住整个数据库。如果数据库中有一个长查询在运行,那么FTWRL就不能获得,会被阻塞,进而阻塞所有的DML操作。此时即使我们kill掉FTWRL全局锁也是无法从阻塞中恢复出来的。另外在我们成功的获得了FTWRL全局锁之后,在copy非事务因为的文件的过程中,整个数据库也是被锁住的。所以我们应该让FTWRL的过程尽量的短。(在copy非事务引擎数据的文件时,会阻塞innodb事务引擎。当然也会阻塞所有其他非事务引擎。)
1> 防止阻塞:
innobackupex 提供了多个选项来避免发生阻塞:
  --ftwrl-wait-timeout=# 替换 --lock-wait-timeout
                      This option specifies time in seconds that innobackupex
                      should wait for queries that would block FTWRL before
                      running it. If there are still such queries when the
                      timeout expires, innobackupex terminates with an error.
                      Default is 0, in which case innobackupex does not wait
                      for queries to complete and starts FTWRL immediately.
  --ftwrl-wait-threshold=# 替换 --lock-wait-threshold
                      This option specifies the query run time threshold which
                      is used by innobackupex to detect long-running queries
                      with a non-zero value of --ftwrl-wait-timeout. FTWRL is
                      not started until such long-running queries exist. This
                      option has no effect if --ftwrl-wait-timeout is 0.
                      Default value is 60 seconds.
--lock-wait-timeout=60 该选项表示:我们在FTWRL时,如果有长查询,那么我们可以最多等待60S的时间,如果60秒之内长查询执行完了,我们就可以成功执行FTWRL了,如果60秒之内没有执行完,那么就直接报错退出,放弃。默认值为0
--lock-wait-threshold=10 该选项表示运行了多久的时间的sql当做长查询;对于长查询最多再等待 --lock-wait-timeout 秒。
--kill-long-queries-timeout=10 该选项表示发出FTWRL之后,再等待多时秒,如果还有长查询,那么就将其kill掉。默认为0,not to kill.
--kill-long-query-type={all|select} 该选项表示我们仅仅kill select语句,还是kill所有其他的类型的长sql语句。
这几个选项,我们没有必要都是有,一般仅仅使用 --lock-wait-timeout=60 就行了。
注意 --lock-* 和 --kill-* 选项的不同,一个是等待多时秒再来执行FTWRL,如果还是不能成功执行就报错退出;一个是已经执行了FTWRL,超时就进行kill。
 
2> 缩短FTWRL全局锁的时间:
--rsync 使用该选项来缩短备份非事务引擎表的锁定时间,如果需要备份的数据库和表数量很多时,可以加快速度。
--rsync           Uses the rsync utility to optimize local file transfers.
                      When this option is specified, innobackupex uses rsync to
                      copy all non-InnoDB files instead of spawning a separate
                      cp for each file, which can be much faster for servers
                      with a large number of databases or tables.  This option
                      cannot be used together with --stream.
3> 并行优化:
  --parallel=# 在备份阶段,压缩/解压阶段,加密/解密阶段,--apply-log,--copy-back 阶段都可以并行       
                      On backup, this option specifies the number of threads
                      the xtrabackup child process should use to back up files
                      concurrently.  The option accepts an integer argument. It
                      is passed directly to xtrabackup's --parallel option. See
                      the xtrabackup documentation for details.
4> 内存优化:
  --use-memory=# 在crash recovery 阶段,也就是 --apply-log 阶段使用该选项
                      This option accepts a string argument that specifies the
                      amount of memory in bytes for xtrabackup to use for crash
                      recovery while preparing a backup. Multiples are
                      supported providing the unit (e.g. 1MB, 1GB). It is used
                      only with the option --apply-log. It is passed directly
                      to xtrabackup's --use-memory option. See the xtrabackup
                      documentation for details.
3> 备份slave:
--safe-slave-backup 
                      Stop slave SQL thread and wait to start backup until
                      Slave_open_temp_tables in "SHOW STATUS" is zero. If there
                      are no open temporary tables, the backup will take place,
                      otherwise the SQL thread will be started and stopped
                      until there are no open temporary tables. The backup will
                      fail if Slave_open_temp_tables does not become zero after
                      --safe-slave-backup-timeout seconds. The slave SQL thread
                      will be restarted when the backup finishes.
 
--safe-slave-backup-timeout=#
                      How many seconds --safe-slave-backup should wait for
                      Slave_open_temp_tables to become zero. (default 300)
 
--slave-info   This option is useful when backing up a replication slave
                      server. It prints the binary log position and name of the
                      master server. It also writes this information to the
                      "xtrabackup_slave_info" file as a "CHANGE MASTER"
                      command. A new slave for this master can be set up by
                      starting a slave server on this backup and issuing a
                      "CHANGE MASTER" command with the binary log position
                      saved in the "xtrabackup_slave_info" file.
 

7. 备份原理:

1)innobackupex 是perl写的脚本,它调用xtrabackup来备份innodb数据库。而xtrabackup是C语言写的程序,它调用了innodb的函数库和mysql客户端的函数库。innodb函数库提供了向数据文件应用的redo log的功能,而mysql客户端函数库提供了解析命令行参数的功能。innobackupex备份innodb数据库的功能,都是通过调用 xtrabackup --backup和xtrabackup --prepare来完成的。我们没有必要直接使用xtrabackup来备份,通过innobackupex更方便。xtrabakup 通过跳转到datadir目录,然后通过两个线程来完成备份过程:
1> log-copy thread: 备份开始时,该后台线程一直监控redo log(每秒check一次redo log),将redo log的修改复制到备份之后的文件 xtrabackup_logfile 中。如果redo log生成极快时,有可能log-copy线程跟不上redo log的产生速度,那么在redo log文件切换进行覆盖时,xtrabakcup会报错。
2> data-file-copy thread: 前后有一个复制data file的线程,注意这里并不是简单的复制,而是调用了innodb函数库,像innodb数据库那样打开数据文件,进行读取,然后每次复制一个page,然后对page进行验证,如果验证错误,会最多重复十次。
当数据文件复制完成时,xtrabackup 停止log-copy 线程,并建立一个文件 xtrabackup_checkpoints记录备份的类型,开始时的lsn和结束时的lsn等信息。
而备份生成的 xtrabackup_binlog_info 文件则含义备份完成时对应的binlog的position信息,类似于:mysql-bin.000002        120
 
在备份开始时记录下LSN,然后一个线程复制数据文件,一个线程监控redo log,复制在备份过程中新产生的redo log。虽然我们的到的数据文件显然不是一致性的,但是利用innodb的crash-recovery功能,应用备份过程中产生的redo log文件,就能得到备份完成时那一刻对应的一致性的数据。
 
注意复制数据文件分成了两个过程:
一个是复制innodb事务引擎的数据文件,是不需要持有锁的;另一个是复制非事务引擎的数据文件和table的定义文件.frm,复制这些文件时,是需要先通过FTWRL,然后在进行复制的,所以会导致整个数据库被阻塞。
增量备份时,是通过对表进行全扫描,比较LSN,如果该page的LSN大于上一次别分时的LSN,那么就将该page复制到table_name.ibd.delta文件中。回复时.delta会和redo log应用到全备是的数据文件中。
增量备份在恢复时,除了最后一次增量备份文件之外,其它的增量备份在应用时,只能前滚,不能执行回滚操作,因为没有提交的事务,可能在下一个增量备份中进行了提交,如果你在上一个增量备份时回滚了,那么下一个增量备份应用时,显然就报错了,因为他无法提交事务,该事务以及被回滚了。
 
8. 总结:
1)权限:
备份需要两个层面的权限,Linux层面的权限,mysql层面的权限。
2)全备和恢复
全备:innobackupex  /backup/xtrabackup/full --user=bkpuser --password=digdeep
应用日志进行prepare: innobackupex --apply-log /backup/xtrabackup/full/2015-11-05_22-38-55/ --user=bkpuser --password=digdeep 
关闭mysqld:
copy-back: innobackupex --copy-back /backup/xtrabackup/full/2015-11-05_22-38-55/ --user=bkpuser --password=digdeep 
修改权限:chown -R mysql:mysql /var/lib/mysql
3)增量备份和恢复:
全备:
innobackupex --user=bkpuser --password=digdeep /backup/xtrabackup/full
第一次增量备份:
innobackupex --incremental /backup/xtrabackup/incr1/ --incremental-basedir=/backup/xtrabackup/full/2015-11-06_11-29-51/ 
--user=bkpuser --password=digdeep 
第二次增量备份:
innobackupex --incremental /backup/xtrabackup/incr2 --incremental-basedir=/backup/xtrabackup/incr1/2015-11-06_11-33-16/ 
--user=bkpuser --password=digdeep
恢复:
应用全备redo log:
innobackupex --apply-log --redo-only /backup/xtrabackup/full/2015-11-06_11-29-51/ --user=bkpuser --password=digdeep
应用第一次增量备份的redo log:
innobackupex --apply-log --redo-only /backup/xtrabackup/full/2015-11-06_11-29-51/ --incremental-dir=/backup/xtrabackup/incr1/2015-11-06_11-33-16/ 
--user=bkpuser --password=digdeep
应用第二次(最后一次)增量备份的redo log:
innobackupex --apply-log /backup/xtrabackup/full/2015-11-06_11-29-51/ --incremental-dir=/backup/xtrabackup/incr2/2015-11-06_11-43-22/ 
--user=bkpuser --password=digdeep
关闭mysqld,
innobackupex --copy-back /backup/xtrabackup/full/2015-11-06_11-29-51/ --user=bkpuser --password=digdeep
4)部分备份 
innobackupex --databases t /backup/xtrabackup/ --user=bkpuser --password=digdeep
innobackupex --apply-log --export /backup/xtrabackup/2015-11-06_15-39-34/ --user=bkpuser --password=digdeep
新建表结构:create table city like t.city;
alter table partial.city discard tablespace;
然后将 city.exp 和 city.ibd 拷贝到 /var/lib/mysql/partial/ 目录下,并修改权限:chown -R mysql:mysql /var/lib/mysql
alter table partial.city import tablespace;
5)point-in-time 恢复
在--copy-back之后,引用binlog文件
mysqlbinlog /backup/xtrabackup/mysql-bin.000002 --start-position=482 > bin.sql
(root@localhost)[(none)]mysql>source bin.sql
6) innobackupex 选项优化/最佳实践
--ftwrl-wait-timeout=60 防止发生阻塞
--rsync 减少FTWRL时间 缩短备份非事务引擎表的锁定时间
--parallel=4  开并行
--use-memory=4G crash recovery 期间使用的内存
 
 

使用 xtrabackup 进行MySQL数据库物理备份的更多相关文章

  1. 关于MySQL数据库的备份方案

    这里简单总结MySQL的备份分为3种:分为冷备份,逻辑备份,热备份. 1.冷备份: 一般主要用于非核心业务,这类业务一般都是允许业务中断的,冷备份的特点就是数度快,恢复时也最为简单.通常直接复物理文件 ...

  2. mysql数据库的备份和还原的总结

    mysql数据库的备份和还原的总结 (来自一运维同事的总结) 1. 备份方式: 热备:数据库在线进行备份,不影响读和写的在线备份方式! 温备:数据库在线进行备份,对表备份时先锁定写操作,仅可以执行读操 ...

  3. 一、MySQL中的索引 二、MySQL中的函数 三、MySQL数据库的备份和恢复 四、数据库设计和优化(重点)

    一.MySQL中的索引###<1>索引的概念 索引就是一种数据结构(高效获取数据),在mysql中以文件的方式存在.存储建立了索引列的地址或者指向. 文件 :(以某种数据 结构存放) 存放 ...

  4. 如何用SQL语句实现Mysql数据库的备份与还原

    以前一直做android客户端的项目,根本没有开发asp.net mvc的开发,现阶段做了一个模块,参数设置,以及数据库的备份与还原.其需求如下: 参数设置 本项参数设置为对自动数据备份进行设置,管理 ...

  5. mysqldump常用于MySQL数据库逻辑备份

    mysqldump常用于MySQL数据库逻辑备份. 1.各种用法说明 A. 最简单的用法: mysqldump -uroot -pPassword [database name] > [dump ...

  6. MYSQL数据库增量备份

    MySQL数据库增量备份,在这之前修改我们的数据库配置文件/etc/my.cnf开启bin-log日志功能即可.接下来是我参考了下网上的一些方法,自己写的,主要还是要能学到他的一些思路和方法. #fu ...

  7. [知了堂学习笔记]_Java代码实现MySQL数据库的备份与还原

    通常在MySQL数据库的备份和恢复的时候,多是采用在cmd中执行mysql命令来实现. 例如: mysqldump -h127.0.0.1 -uroot -ppass test > d:/tes ...

  8. mysql数据库的备份和恢复

    Mysql数据库的备份和恢复 1.备份单个数据库 mysql数据库自带了一个很好用的备份命令,就是mysqldump,它的基本使用如下: 语法:mysqldump –u <用户名> -p ...

  9. 使用percona-xtrabackup工具对mysql数据库的备份方案

    使用percona-xtrabackup工具对mysql数据库的备份方案 需要备份mysql的主机 172.16.155.23存放备份mysql的主机 172.16.155.22 目的:将155.23 ...

随机推荐

  1. request的各种方法大全

    request.setAttribute("result", district);//放进作用域,可以用el表达式在页面展示.(名字,调用方法的结果) pageContext.re ...

  2. PHP旧系统基于命名空间重构经验

    命名空间其实只是一个形式,最终目的是重构代码,但这个过程想要一蹴而就是不可能的. 一开始给了一个伪命题:基于ThinkPHP的重构(不要问为什么).经过一段的实践,发现这是一个大错特错的思维方式,其中 ...

  3. java Servlet(续)

    一.web.xml配置 由于需用户需要通过URL访问架设好的Servlet,所以我们必须将servlet映射到一个URL地址上, 比如上面的配置文件我们就可以通过:http://localhost:8 ...

  4. 第 22 章 CSS3 渐变效果

    学习要点: 1.线性渐变 2.径向渐变 主讲教师:李炎恢 本章主要探讨 HTML5 中 CSS3 背景渐变功能,主要有两种渐变方式:线性渐变和径向(放射性)渐变. 一.线性渐变 CSS3 提供了 li ...

  5. No.014:Longest Common Prefix

    问题: Write a function to find the longest common prefix string amongst an array of strings. 官方难度: Eas ...

  6. 成为 Web 开发大师你必须知道的 7 件事情

    曾经是这样的,懂点编码,并可以偶尔耍点酷,那么你就会被认为是一个Web开发大师.但是现在,情况再也不是这样的了.Web开发已经朝着主流方向发展,开发人员数量显著增加.这意味着,如果你想成为这个领域的大 ...

  7. 一款经典的jQuery slidizle 幻灯片

    jQuery广告幻灯片进度条,水平/左右切换,垂直/上下切换,自动播放,缩略图列表切换 在线实例 默认效果 水平/左右切换 垂直/上下切换 循环 自动播放 缩略图 进度条 回调函数 使用方法 < ...

  8. sharepoint 修改AD密码

    sharepoint 修改AD密码 下面是添加添加“空元素”代码: 第一个<CustomAction>是添加修改密码项目 第二个<CustomAction>是添加js修改脚本 ...

  9. Android SQL语句实现数据库的增删改查

    本文介绍android中的数据库的增删改查 复习sql语法: * 增 insert into info (name,phone) values ('wuyudong','111') * 删 delet ...

  10. 你真的了解UIGestureRecognizer吗?

    一:首先查看一下关于UIGestureRecognizer的定义 //当前手势状态 typedef NS_ENUM(NSInteger, UIGestureRecognizerState) { //尚 ...