溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶(hù)服務(wù)條款》

全量備份與增量備份實(shí)踐

發(fā)布時(shí)間:2020-03-04 10:43:20 來(lái)源:網(wǎng)絡(luò) 閱讀:927 作者:淺景塵 欄目:MySQL數(shù)據(jù)庫(kù)

1.1 全備備份與恢復(fù)全備實(shí)踐

#######################################################################################

1、安裝Xtrabackup備份命令

wget -O /etc/yum.repos.d/epel.repo  http://mirrors.aliyun.com/repo/epel-6.repo

yum -y install perl perl-devel libaio libaio-develperl-Time-HiRes perl-DBD-MySQL

 

wget https://www.percona.com/downloads/XtraBackup/Percona-XtraBackup-2.4.4/binary/redhat/6/x86_64/percona-xtrabackup-24-2.4.4-1.el6.x86_64.rpm

yum -y install percona-xtrabackup-24-2.4.4-1.el6.x86_64.rpm

innobackupex ******

2、創(chuàng)建logs目錄并配置權(quán)限

mkdir /application/mysql/logs -p

chown -R /mysql.mysql /application/mysql/logs

3、配置/etc/my.cnf文件

[client]         

user=root        

password=oldboy123

[mysqld]

basedir= /application/mysql/  

datadir= /application/mysql/data/

###########binlog############

log_bin = /application/mysql/logs/oldboy-bin

expire_logs_days = 7   

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

 

[mysqld_safe]

log-error = /application/mysql/logs/oldboy.err

配置完成重啟生效

[root@db02 data]#/etc/init.d/mysqld restart

Shutting down MySQL.. SUCCESS!

Starting MySQL... SUCCESS!

4、全被備份

mkdir /server/backup -p

innobackupex --defaults-file=/etc/my.cnf--user=root --password=oldboy123--socket=/application/mysql-5.6.34/tmp/mysql.sock --no-timestamp/server/backup/full

5、恢復(fù)數(shù)據(jù)前的準(zhǔn)備(合并xtrabackup_log_file和備份的物理文件)

innobackupex --apply-log --use-memory=32M/server/backup/full/

停庫(kù)

/etc/init.d/mysqld stop

lsof -i :3306

破壞數(shù)據(jù):

cd /application/mysql/

mv data /opt/

恢復(fù):

cp -a /server/backup/full/ /application/mysql/data

chown -R mysql.mysql /application/mysql/data

啟動(dòng)

/etc/init.d/mysqld start

mysql -e "select * from oldboy.test"

數(shù)據(jù)恢復(fù)成功。

1.2 實(shí)現(xiàn)增量備份及恢復(fù):

環(huán)境準(zhǔn)備:

du -sh /application/mysql/data/

free -m

cd /server/backup/

\rm -rf *

 

 

1、全量備份(周一0點(diǎn))

innobackupex --defaults-file=/etc/my.cnf--user=root --password=oldboy123--socket=/application/mysql-5.6.34/tmp/mysql.sock --no-timestamp/server/backup/base_full

 

2、第一次增量備份(周二0點(diǎn))

a.準(zhǔn)備

use oldboy

mysql> insert into test values(8,'outman');   插入兩條數(shù)據(jù)

Query OK, 1 row affected (0.00 sec)

 

mysql> insert into test values(9,'outgirl');

Query OK, 1 row affected (0.00 sec)

select *from test;

b.增量

innobackupex --defaults-file=/etc/my.cnf--user=root --password=oldboy123--socket=/application/mysql-5.6.34/tmp/mysql.sock --no-timestamp--incremental-basedir=/server/backup/base_full --incremental/server/backup/one_inc

 

2、第二次增量

mysql> use oldboy

mysql> insert into test values(10,'two_inc1');

Query OK, 1 row affected (0.00 sec)

mysql> insert into test values(11,'two_inc2');

Query OK, 1 row affected (0.00 sec)

 

innobackupex --defaults-file=/etc/my.cnf--user=root --password=oldboy123--socket=/application/mysql-5.6.34/tmp/mysql.sock --no-timestamp --parallel=3--incremental-basedir=/server/backup/one_inc/ --incremental/server/backup/two_inc

 

增量恢復(fù):

innobackupex --apply-log --use-memory=32M--redo-only /server/backup/base_full/

innobackupex --apply-log --use-memory=32M--redo-only --incremental-dir=/server/backup/one_inc /server/backup/base_full/

innobackupex --apply-log --use-memory=32M--incremental-dir=/server/backup/two_inc /server/backup/base_full/正式數(shù)據(jù)文件

 

恢復(fù)過(guò)程:

[root@db02 backup]# /etc/init.d/mysqld stop

Shutting down MySQL.. SUCCESS!

[root@db02 backup]# cd /application/mysql

[root@db02 mysql]# mv data /tmp/

 

 

[root@db02 mysql]# /bin/cp -a/server/backup/base_full data

[root@db02 mysql]# chown -R mysql.mysql data

[root@db02 mysql]# /etc/init.d/mysqld start

Starting MySQL......... SUCCESS!

 

[root@db02 mysql]# mysql -e "select * fromoldboy.test;"

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

| id | name    |

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

|  1 |oldboy   |

|  2 |oldgirl  |

|  3 |inca     |

|  4 |zuma     |

|  5 |kaka     |

|  6 |bingbing |

|  7 |xiaoting |

|  8 |outman   |

|  9 |outgirl  |

| 10 | two_inc1 |

| 11 | two_inc2 |

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

由此可以看到增量恢復(fù)數(shù)據(jù)恢復(fù)成功!


向AI問(wèn)一下細(xì)節(jié)

免責(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)容。

AI