www.fromdual.

com

MySQL Backup und Restore
DOA !onferen" 2#1$ %&rn'er(

Ol) Senn*auser
Sen)or MySQL +onsultant, -romDual m'.

ol).senn*auser/fromdual.com

1 / 22

0'er -romDual

● ● ● ●

m'.
alera alera

www.fromdual.com

-romDual ')etet neutral und una'*1n()(2
Beratun( f&r MySQL und Support f&r MySQL und MySQL Sc*ulun(en

Remote3DBA D)enstle)stun(en

4artner der Open Data'ase All)ance 5ODBA.or(6 Oracle S)l7er 4artner 5O4%6

www.fromdual.com
2 / 22

8nsere !unden

www.fromdual.com

$ / 22

:n*alt
MySQL Backup
➢ ➢ ➢ ➢ ➢ ➢ ➢ ➢

www.fromdual.com

;twas Backup <*eor)e +old Backup mysqldump L=M Snaps*ot >tra'ackup / M;B M/S Repl)kat)on Restore 4o)nt3)n3<)me3Reco7ery

9 / 22

@arum BackupA
● ●

www.fromdual.com

Backups )st f&r M1dc*enB @)r *a'en .A, 'rauc*en da*er ke)n BackupB

.ardware kaputt 5(an" sc*nell tot6 +48, RAM, :/O !ontroller lan(sam st)r'tA ;ure ;ntw)ckler fol(endes tun2 UPDATE employee SET bonus = 0; WHERE id = 42;

@as pass)ert, wenn2
● ●

● ● ●

@er *at e)n Backup34ro"ess )mplement)ertA @)e mac*t :*r BackupA @er testet den Restore 4ro"ess &'er*aupt/manc*mal/re(elm1ss)(A
? / 22

Lo()sc* 7s. 4*ys)sc*

www.fromdual.com

2 untersc*)edl)c*e !on"epte 5una'*1n()( 7on MySQL6 Lo()sc*es Backup

mysqldump D Emensc*enles'arF Gede Row w)rd an(elan(tB Date)3!op)e L=M Snaps*ot H Date)3!op)e >tra'ackup, MySQL ;nterpr)se Backup 5M;B6

4*ys)sc*es Backup
● ● ●

D B)n1rdaten, Block3 oder Date)3we)ses !op)eren
C / 22

Backup3=ar)anten
MySQL kennt 9 ½ Backup3=ar)anten2

www.fromdual.com

Date)en kop)eren 'e) (estoppter DB 5p*ys.6 mysqldump )m laufenden Betr)e' 5lo(.6 L=M Snaps*ot Juas) )m laufenden Betr)e' 5p*ys.6 >tra'ackup / M;B )m laufenden Betr)e' 5p*ys.6 Master/Sla7e Repl)kat)on D s)e*e =ar)ante 1 3 9
I / 22

MySQL +old Backup
● ●

www.fromdual.com

4*ys)sc*es Date)3!op)eren 'e) (estoppter DB =or(e*en2
● ● ●

Daten'ank stoppen cp -r $datadir /backup Daten'ank starten Se*r e)nfac*, )mmer kons)stent, Ser7)ce %:+.< 7erf&('ar, @artun(sfenster erforderl)c*, sc*nell 'e) (rossen Datenmen(en, kann m)t L=M kom')n)ert werden, sc*neller Restore.
K / 22

;)(ensc*aften2

Demo

mysqldump

www.fromdual.com

Lo()sc*es Daten'ank3Backup )m laufenden Betr)e'
● ●

:nnoDB2 'lock)erun(sfre) My:SAM2 read3only em)sc* D My:SAM mysqldump --all-databases {--single-transaction | --lock-all-tables} ... > /backup/full_dump.sql Se*r e)nfac*, )m laufenden Betr)e' 5'e) :nnoDB6, 'lock)erend f&r Sc*re)'"u(r)ffe 5My:SAM6, %:+.< (ee)(net f&r (rosse Datenmen(en, lan(samer Restore, )nkons)stentes Backup mM(l)c*

=or(e*en2

;)(ensc*aften2

Demo
L / 22

mysqldump
cp /etc/my.cnf $BACKUP_DIR/my_$BACKUP_TIMESTAMP.cnf

www.fromdual.com

# for MyISAM mysqldump --user=root --all-databases --flush-privileges --lock-all-tables \ --master-data=1 --flush-logs --triggers --routines --events \ --hex-blob > $BACKUP_DIR/full_dump_$BACKUP_TIMESTAMP.sql # for InnoDB mysqldump --user=root --all-databases --flush-privileges --single-transaction \ --master-data=1 --flush-logs --triggers --routines --events \ --hex-blob > $BACKUP_DIR/full_dump_$BACKUP_TIMESTAMP.sql

1# / 22

L=M Snaps*ot

www.fromdual.com

4*ys)sc*es Juas)3*ot Backup )m laufenden Betr)e'

Block)ert (an" kur" f&rs Sc*re)'en FLUSH TABLES WITH READ LOCK; Start snaps*ot UNLOCK TABLES; ;twas kompl)")erter, )mmer !ons)stent, (an" kur"e Sc*re)'3 'lock)erun( erforderl)c*, sc*nell 'e) (rossen Datenmen(en, sc*neller Restore, :nnoDB +ras*3Reco7ery erforderl)c*. mylvmbackup 5*ttp2//www.len"(.net/myl7m'ackup/6
11 / 22

=or(e*en2
● ●

;)(ensc*aften2

<ool2

Demo

>tra'ackup / M;B
● ●

www.fromdual.com

>tra'ackup / MySQL ;nterpr)se Backup 4*ys)sc*es Backup )m laufenden Betr)e'
● ● ●

Bas)ert auf :nnoDB Reco7ery Mec*an)smus :nnoDB2 'lock)erun(sfre) My:SAM2 read3only innobackupex /backup/ innobackupex --apply-log /backup/ Rec*t e)nfac*, )mmer !ons)stent, )m laufenden Betr)e' 5'e) :nnoDB6, 'lock)erend f&r Sc*re)'"u(r)ffe 5My:SAM6, sc*nell 'e) (rossen Datenmen(en, sc*neller Restore.
12 / 22

=or(e*en2
● ●

;)(ensc*aften2

Demo

Master/Sla7e Repl)kat)on
Appl)kat)on

www.fromdual.com

Master

async

Backup3 Sla7e

Datenkons)sten" auf Sla7eA

1$ / 22

Restore

www.fromdual.com

2 =ar)anten 5A'*1n()( 7om Backup62 a6 Restore 7on Dump

mysqldump

'6 Restore 7on Date)3!op)en
● ● ●

+old Backup L=M Snaps*ot >tra'ackup/M;B
19 / 22

Restore 7on Dump

www.fromdual.com

Backup erstellt m)t mysqldump =or(e*en2

rm -rf $datadir mysql_install_db --datadir=/var/lib/mysql service mysql start mysql -u root < /backup/full_dump.sql !ann 'e) (rossen Datenmen(en S;;;.R lan(e dauern... D <estenB
1? / 22

;)(ensc*aften2

Demo

Restore 7on p*ys. Backup

www.fromdual.com

Backup 7on +old Backup, L=M Snaps*ot, >tra'ackup =or(e*en2

rm -rf $datadir cp -R /backup/full_backup . service mysql start Restore3Dauer2 proport)onal "ur Datenmen(e

;)n(ensc*aften2

Demo
1C / 22

4o)nt3)n3<)me3Reco7ery 54:<R6
Appl)cat)on Appl)cat)on Appl)cat)on

www.fromdual.com

log_bin = bin-log

mysJld

')n3lo(.1

')n3lo(.2

...

')n3lo(.n

pos/t)meA

A
192## t
1I / 22

#22##

full 'ackup

<)pps und <r)cks :
● ● ●

www.fromdual.com

Backups re(elm1ss)( 5t1(l)c*A6 mac*enB B)nary Lo( e)nsc*alten 5log_bin6 B)nary Lo( 4os)t)on "u Backup merken 5-master-data6 Lesen und Sc*re)'en 7on untersc*)edl)c*en 4latten Backups und B)nary Lo(s n)c*t auf sel'en 4latten w)e Daten a'le(en. DB Backup m)t -)lesystem3Backup we(s)c*ern 5<)m)n( 'eac*ten6 Sc*lec*te ;rfa*run( m)t mysqldump d)rekt auf %-S
1K / 22

<)pps und <r)cks ::

www.fromdual.com

!orrupte Daten werden 'e) p*ys)sc*en Backups n)c*t 'emerkt2

L=M Snaps*ot, :nnoDB !orrupt)onenA mysqldump --all-databases > /dev/null :st n)c*t sooo teuerB mysqldump --all-databases --no-data :ns =+S e)nc*eckenA

Strukur Dump 7on Ne)t "u Ne)t erstellen.
● ● ●

● ●

Restore2 @)r fan(en an m)t ... e)nem BackupB @e)tere <)pps aus ;urem ;rfa*run(ssc*at"A
1L / 22

Backup3<est
4rodukt)on 4rod QA

www.fromdual.com

;ntw)cklun( <est De7

'ck

DBA

n1c*tl)c*er Restore TestDB1: TestDB2: DevDBa: DevDBb: DevDBc: ja nein ja nein ja

;ntw)ckler

2# / 22

@)r suc*en noc*2

www.fromdual.com

;rfa*rene/r MySQL DBA / Open3Source ;nt*us)ast/)n f&r MySQL Support / remote3 DBA
und

uter +HH ;ntw)ckler/)n 5m)t Aff)n)t1t "u DBs, MySQL, Repl)kat)on und +luster6
21 / 22

QOA
-ra(en A D)skuss)onA
@)r *a'en Ne)t f&r e)n persMnl)c*es

www.fromdual.com

espr1c*...

-romDual ')etet neutral und una'*1n()(2

Beratun( Remote3DBA Support f&r MySQL, Sc*ulun( alera, 4ercona Ser7er und Mar)aDB

www.fromdual.com/presentat)ons
22 / 22