Introduction:
Xtrabackup is a tool used to back up InnoDB data. It supports online Hot Backup (data read/write is not affected during Backup) and is a good alternative to InnoDB hotbackup.
Xtrabackup has two main tools: xtrabackup and innobackupex.
(1) xtrabackup can only back up InnoDB and xtradb data tables, but cannot back up MyISAM data tables.
(2) innobackupex-1.5.1 encapsulates xtrabackup, which is a script encapsulation, so InnoDB and MyISAM can be backed up at the same time, but a read lock is needed when processing MyISAM
(3) Help: http://www.percona.com/docs/wiki/percona-xtrabackup:start
Environment: centos 5.4,xtrabackup-1.6.tar.gz
1. First download from http://www.percona.com/
Wget http://www.percona.com/downloads/XtraBackup/XtraBackup-1.6/Linux/binary/i686/xtrabackup-1.6.tar.gz
2. Check whether the mysql version is installed on the server. If not, install MySQL.
Datadir =/var/lib/MySQL must exist in my. CNF.
3. Start to install xtrabackup
1) decompress
CD/qeedoodb/setup
Tar zxvf xtrabackup-1.6.tar.gz
2) copy the innobackupex, xtrabackup, and xtrabackup_51 tools to/usr/bin.
CP/qeedoodb/Setup/xtrabackup-1.6/bin/innobackupex/usr/bin/innobackupex
CP/qeedoodb/Setup/xtrabackup-1.6/bin/xtrabackup/usr/bin/xtrabackup
CP/qeedoodb/Setup/xtrabackup-1.6/bin/xtrabackup_51/usr/bin/xtrabackup_51
4. Back up and compress the package
Innobackupex -- user = root -- Password = 123456 -- defaults-file =/etc/My. CNF -- database = zztx -- stream = tar/data/back_data/2>/data/back_data/zztx. log | gzip 1>/data/back_data/zztx.tar.gz
Note:
-- Database = zztx back up the zztx database separately. If this parameter is not added, the full database is backed up.
2>/data/back_data/zztx. Log: Write the output information to the log.
1>/data/back_data/zztx.tar.gz package, compress, and store it in this file
Here, you can write a script for backup (backup. Sh)
#! /Bin/sh
Echo "Start backup..." 'date'
Log = zztx01 _ 'date + % Y % m % d % H % M'. Log
STR = zztx01 _ 'date when policyymm1_d1_hsf-m'.tar.gz
Innobackupex -- user = root -- Password = 123456 -- defaults-file =/etc/My. CNF -- database = zztx -- stream = tar/data/back_data/2>/data/back_data/$ log | gzip 1>/data/back_data/$ Str
Echo "backup completed..." 'date'
5. Restore data
1) Stop the database first: Service mysqld stop
2) decompress tar-izxvf zztx.tar.gz-C/data/back_data/DB/(without dB, mkdir/data/back_data/DB/is required /)
3) Restore innobackupex -- user = root -- password -- defaults-file =/etc/My. CNF -- apply-log/data/back_data/DB/(the command for the -- apply-log option is to start the MySQL service on a backup)
Innobackupex -- user = root -- password -- defaults-file =/etc/My. CNF -- copy-back/data/back_data/DB/(-- copy-back option command copy data, index, log to my. the initial position specified in the CNF file .)
4) Attach chown-r MySQL. MySQL/var/lib/MySQL /*
5) Restart Database Service mysqld restart
6) Delete junk CD/var/lib/MySQL/& RM xtrabackup *
Go to the database and check everything. OK ~