您好,登錄后才能下訂單哦!
下文我給大家簡(jiǎn)單講講關(guān)于安裝Xtrabackup實(shí)現(xiàn)備份MySQL詳細(xì)步驟,大家之前了解過相關(guān)類似主題內(nèi)容嗎?感興趣的話就一起來看看這篇文章吧,相信看完安裝Xtrabackup實(shí)現(xiàn)備份MySQL詳細(xì)步驟對(duì)大家多少有點(diǎn)幫助吧。
一、安裝Xtrabackup
# wget --no-check-certificate http://www.percona.com/downloads/percona-release/redhat/0.1-4/percona-release-0.1-4.noarch.rpm # rpm -ivh percona-release-0.1-4.noarch.rpm # yum list | grep percona # yum -y install percona-xtrabackup-24
二、安裝MySQL
1.安裝MySQL
# yum -y install http://repo.mysql.com//mysql57-community-release-el7-9.noarch.rpm # yum list |grep mysql-community # yum -y install mysql mysql-server mysql-devel
2.更改時(shí)間戳設(shè)置
# cat /var/log/mysqld.log |grep "timestamp" [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). # vi /etc/my.cnf explicit_defaults_for_timestamp=true ##顯示指定默認(rèn)值為timestamp類型的字段
3.啟動(dòng)MySQL
# systemctl start mysqld # systemctl status mysqld
4.配置MySQL密碼
# mysql Enter password: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
a.新版本MySQL安裝完成后會(huì)生成臨時(shí)的初始密碼
# grep 'temporary password' /var/log/mysqld.log [Note] A temporary password is generated for root@localhost: qhAnfco2o)HB
修改MySQL密碼
注意:MySQL 5.7默認(rèn)安裝了密碼安全檢查插件(validate_password),默認(rèn)密碼檢查策略要求密碼必須包含:大小寫字母、數(shù)字和特殊符號(hào),并且長(zhǎng)度不能少于8位。
MySQL官網(wǎng)MySQL 5.7密碼策略詳細(xì)說明:
http://dev.mysql.com/doc/refman/5.7/en/validate-password-options-variables.html#sysvar_validate_password_policy
b.修改密碼策略
# vi /etc/my.cnf validate_password_policy = LOW ##密碼長(zhǎng)度不少于8位即可 # systemctl restart mysqld # mysql -u root -p mysql> set password for 'root'@'localhost'=password('12345678');
c.官方數(shù)據(jù)庫示例
# wget http://downloads.mysql.com/docs/sakila-db.tar.gz # tar -zxvf sakila-db.tar.gz sakila-db/ sakila-db/sakila-data.sql sakila-db/sakila-schema.sql sakila-db/sakila.mwb [root@localhost ~]# pwd /root # mysql -u root -p mysql> source /root/sakila-db/sakila-schema.sql ##還原數(shù)據(jù)庫結(jié)構(gòu) mysql> source /root/sakila-db/sakila-data.sql ##將數(shù)據(jù)寫入數(shù)據(jù)庫
三、innobackupex常用命令
--backup 默認(rèn)選項(xiàng)
--defaults-file 指定要備份的mysql實(shí)例的my.cnf文件,必須為第一個(gè)選項(xiàng)
--port 端口
--socket 連接套字節(jié)的位置,默認(rèn)為/var/lib/mysql/mysql.sock
--host 主機(jī)
--no-timestamp 指定了這個(gè)選項(xiàng)備份會(huì)直接備份在BACKUP-DIR,不再創(chuàng)建時(shí)間戳文件夾
--target-dir 指定了這個(gè)選項(xiàng)備份會(huì)直接備份在BACKUP-DIR,不再創(chuàng)建時(shí)間戳文件夾
--use-memory 指定備份所用內(nèi)存大小,默認(rèn)為100M,與--apply-log同用
--apply-log 從備份恢復(fù)
--apply-log-only 在恢復(fù)時(shí),停止恢復(fù)進(jìn)程不進(jìn)行LSN,只使用log
--copy-back 復(fù)制備份文件
--incremental 建立增量備份
--incremental-basedir=DIRECTORY
指定一個(gè)全庫備份的目錄作為增量備份的基礎(chǔ)數(shù)據(jù)庫
--incremental-dir=DIRECTORY
指定增量備份與全庫備份合并建立一個(gè)新的全備目錄
--prepare 從backup恢復(fù)
--compress 壓縮選項(xiàng)
四、xtrabackup備份后的主要文件
(1)xtrabackup_checkpoints —— 備份類型(如完全或增量)、備份狀態(tài)(如是否已經(jīng)為prepared狀態(tài))和LSN(日志序列號(hào))范圍信息;
每個(gè)InnoDB頁(通常為16k大小)都會(huì)包含一個(gè)日志序列號(hào),即LSN。LSN是整個(gè)數(shù)據(jù)庫系統(tǒng)的系統(tǒng)版本號(hào),每個(gè)頁面相關(guān)的LSN能夠表明此頁面最近是如何發(fā)生改變的。
(2)xtrabackup_binlog_info —— mysql云服務(wù)器當(dāng)前正在使用的二進(jìn)制日志文件及至備份這一刻為止二進(jìn)制日志事件的位置。
(3)xtrabackup_binlog_pos_innodb —— 二進(jìn)制日志文件及用于InnoDB或XtraDB表的二進(jìn)制日志文件的當(dāng)前position。
(4)xtrabackup_binary —— 備份中用到的xtrabackup的可執(zhí)行文件。
(5)backup-my.cnf —— 備份命令用到的配置選項(xiàng)信息。
五、Innobackupex備份
1.創(chuàng)建全備
# innobackupex --defaults-file=/etc/my.cnf --user=root --password=12345678 /backup/ ...... completed OK!
2.應(yīng)用全備日志
# innobackupex --apply-log /backup/2017-04-03_12-45-44/ ...... completed OK!
3.查看備份狀態(tài)
# cat /backup/2017-04-03_12-45-44/xtrabackup_checkpoints backup_type = full-prepared ##全備 from_lsn = 0 ##備份開始點(diǎn) to_lsn = 9692219 ##備份結(jié)束點(diǎn) last_lsn = 9692228 compact = 0 recover_binlog_info = 0
4.查看二進(jìn)制日志事件信息
# cat /backup/2017-04-03_12-45-44/xtrabackup_info uuid = 694e5590-1828-11e7-81d2-000c291bd2a1 name = tool_name = innobackupex tool_command = --defaults-file=/etc/my.cnf --user=root --password=... /backup/ tool_version = 2.4.6 ibbackup_version = 2.4.6 server_version = 5.7.17 start_time = 2017-04-03 21:34:09 end_time = 2017-04-03 21:34:13 lock_time = 0 binlog_pos = innodb_from_lsn = 0 innodb_to_lsn = 9692219 partial = N incremental = N format = file compact = N compressed = N encrypted = N
5.進(jìn)行全備恢復(fù)
a.刪除數(shù)據(jù)庫、停止并破壞MySQL
# mysql -u root -p mysql> show databases; mysql> drop database sakila; Query OK, 30 rows affected (0.59 sec) # systemctl stop mysqld # cp -R /var/lib/mysql /root # rm -rf /var/lib/mysql
b.恢復(fù)全備
# innobackupex --copy-back /backup/2017-04-03_21-34-08/ ...... completed OK! # chown -R mysql.mysql /var/lib/mysql # systemctl start mysqld # mysql -u root -p mysql> show databases;
注:如無法啟動(dòng)SQL,可能是SELINUX的問題
# vim /etc/selinux/config SELINUX=disabled
六、Innobackupex增量備份
1.創(chuàng)建數(shù)據(jù)庫和表
# mysql -u root -p mysql> create database abc; mysql> use abc; mysql> create table plus (id int(10),name varchar(20),phone char(11),birth date); mysql> show tables; mysql> insert into plus values(1,'tom',12345678901,'2001-01-01'); mysql> insert into plus values(2,'jack',12345678911,'2011-11-11'); mysql> select * from plus; +------+------+-------------+------------+ | id | name | phone | birth | +------+------+-------------+------------+ | 1 | tom | 12345678901 | 2001-01-01 | | 2 | jack | 12345678911 | 2011-11-11 | +------+------+-------------+------------+ 2 rows in set (0.00 sec)
2.基于全備進(jìn)行增量備份
# innobackupex --defaults-file=/etc/my.cnf --user=root --password=12345678 --incremental --incremental-basedir=/backup/2017-04-03_21-34-08/ /backup/001/ ...... completed OK! # cat /backup/001/2017-04-03_21-41-27/xtrabackup_checkpoints backup_type = incremental ##增量備份 from_lsn = 9692219 ##備份開始點(diǎn) to_lsn = 9699700 ##備份結(jié)束點(diǎn) last_lsn = 9699709 compact = 0 recover_binlog_info = 0
3.應(yīng)用全備日志
# innobackupex --defaults-file=/etc/my.cnf --user=root --password=12345678 --apply-log-only /backup/2017-04-03_21-34-08/ ...... completed OK!
4.應(yīng)用第一次增量備份日志
# innobackupex --defaults-file=/etc/my.cnf --user=root --password=12345678 --apply-log-only /backup/2017-04-03_21-34-08/ --incremental-dir=/backup/001/ ...... completed OK!
5.基于全備進(jìn)行第一次增量備份恢復(fù)
# systemctl stop mysqld # rm -rf /var/lib/mysql # innobackupex --copy-back /backup/2017-04-03_21-34-08/2017-04-03_21-44-08/ ...... completed OK! # chown -R mysql.mysql /var/lib/mysql # systemctl start mysqld # mysql -u root -p mysql> show databases; mysql> use abc; mysql> select * from plus; +------+------+-------------+------------+ | id | name | phone | birth | +------+------+-------------+------------+ | 1 | tom | 12345678901 | 2001-01-01 | | 2 | jack | 12345678911 | 2011-11-11 | +------+------+-------------+------------+ 2 rows in set (0.00 sec)
6.基于第一次增量備份進(jìn)行備份
a.向表中添加數(shù)據(jù)
# mysql -u root -p mysql> use abc; mysql> insert into plus values(3,'rose',12345678912,'2012-12-12'); mysql> insert into plus values(4,'jordan',12345678923,'2012-12-23');
b.應(yīng)用第二次增量備份日志
# innobackupex --defaults-file=/etc/my.cnf --user=root --password=12345678 --apply-log-only /backup/2017-04-03_21-34-08/ --incremental-dir=/backup/002/ ...... completed OK!
c.查看備份狀態(tài)
# cat /backup/002/2017-04-03_21-48-54/xtrabackup_checkpoints backup_type = incremental from_lsn = 9699700 to_lsn = 9696137 last_lsn = 9696146 compact = 0 recover_binlog_info = 0
d.基于全備份和第一次增量備份,恢復(fù)第二次增量備份
# systemctl stop mysqld # rm -rf /var/lib/mysql # innobackupex --copy-back /backup/2017-04-03_21-34-08/2017-04-03_21-50-11/ ...... completed OK! # chown -R mysql.mysql /var/lib/mysql # systemctl start mysqld # mysql -u root -p mysql> show databases; mysql> use abc; mysql> select * from plus; +------+--------+-------------+------------+ | id | name | phone | birth | +------+--------+-------------+------------+ | 1 | tom | 12345678901 | 2001-01-01 | | 2 | jack | 12345678911 | 2011-11-11 | | 3 | rose | 12345678912 | 2012-12-12 | | 4 | jordan | 12345678923 | 2012-12-23 | +------+--------+-------------+------------+ 4 rows in set (0.00 sec)
七、Xtrabackup備份
1.創(chuàng)建全備
# xtrabackup --defaults-file=/etc/my.cnf --user=root --password=12345678 --backup --target-dir=/backup/full ...... completed OK!
2.應(yīng)用全備日志
# xtrabackup --defaults-file=/etc/my.cnf --prepare --user=root --password=12345678 --apply-log-only --target-dir=/backup/full ...... completed OK!
3.查看備份狀態(tài)
# cat /backup/full/xtrabackup_checkpoints backup_type = log-applied from_lsn = 0 to_lsn = 9692712 last_lsn = 9692721 compact = 0 recover_binlog_info = 0
4.恢復(fù)備份
# systemctl stop mysqld # rm -rf /var/lib/mysql # cd /backup/full/ # rsync -rvt --exclude 'xtrabackup_checkpoints' --exclude 'xtrabackup_logfile' ./ /var/lib/mysql sent 151722380 bytes received 6476 bytes 15971458.53 bytes/sec total size is 151681109 speedup is 1.00 # chown -R mysql.mysql /var/lib/mysql # systemctl start mysqld # mysql -u root -p mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | abc | | mysql | | performance_schema | | sakila | | sys | +--------------------+ 6 rows in set (0.09 sec)
八、Xtrabackup增量備份
1.第一次增量備份
# mysql -u root -p mysql> create database ball; mysql> use ball; mysql> create table superstar (id int(5),name varchar(20),number int(2),city varchar(20),team varchar(10)); mysql> insert into superstar values(1,'Jordan',23,'Chicago','Bulls'); mysql> insert into superstar values(2,'Yao',11,'Houston','Rockets');
2.應(yīng)用第一次增量備份日志
# xtrabackup --defaults-file=/etc/my.cnf --user=root --password=12345678 --backup --target-dir=/backup/inc1 --incremental-basedir=/backup/full ...... completed OK!
3.查看備份狀態(tài)
# cat /backup/inc1/xtrabackup_checkpoints backup_type = incremental from_lsn = 9692712 to_lsn = 9763373 last_lsn = 9763382 compact = 0 recover_binlog_info = 0
4.第二次增量備份
# mysql -u root -p mysql> use ball; mysql> insert into superstar values(3,'Russell',6,'Boston','Celtics'); mysql> insert into superstar values(4,'Pierce',34,'Boston','Celtics');
5.應(yīng)用第二次增量備份日志
# xtrabackup --defaults-file=/etc/my.cnf --user=root --password=12345678 --backup --target-dir=/backup/inc2 --incremental-basedir=/backup/inc1/
6.查看備份狀態(tài)
# cat /backup/inc2/xtrabackup_checkpoints backup_type = incremental from_lsn = 9763373 to_lsn = 9766964 last_lsn = 9766973 compact = 0 recover_binlog_info = 0
7.準(zhǔn)備第一次增量備份
# xtrabackup --defaults-file=/etc/my.cnf --user=root --password=12345678 --prepare --apply-log-only --target-dir=/backup/full --incremental-dir=/backup/inc1 ...... completed OK!
8.準(zhǔn)備第二次增量備份
# xtrabackup --defaults-file=/etc/my.cnf --user=root --password=12345678 --prepare --target-dir=/backup/full --incremental-dir=/backup/inc2 ...... completed OK!
9.合并恢復(fù)備份
# systemctl stop mysqld # rm -rf /var/lib/mysql # xtrabackup --defaults-file=/etc/my.cnf --user=root --password=12345678 --copy-back --target-dir=/backup/full ...... completed OK! # chown -R mysql.mysql /var/lib/mysql # systemctl start mysqld # mysql -u root -p mysql> use ball; mysql> select * from superstar; +------+---------+--------+---------+---------+ | id | name | number | city | team | +------+---------+--------+---------+---------+ | 1 | Jordan | 23 | Chicago | Bulls | | 2 | Yao | 11 | Houston | Rockets | | 3 | Russell | 6 | Boston | Celtics | | 4 | Pierce | 34 | Boston | Celtics | +------+---------+--------+---------+---------+ 4 rows in set (0.00 sec)
大家覺得安裝Xtrabackup實(shí)現(xiàn)備份MySQL詳細(xì)步驟這篇文章怎么樣,是否有所收獲。如果想要了解更多相關(guān),可以繼續(xù)關(guān)注我們的行業(yè)資訊板塊。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。