GTID

Global Transaction Identifier

๊ฐ๊ฐ์˜ ํŠธ๋ Œ์ ์…˜๋“ค์€ ๊ณ ์œ ํ•œ ์ „์—ญ์‹๋ณ„์ž๋ฅผ ๊ฐ–๊ฒŒ ๋œ๋‹ค.

GTID = source_id:transaction_Id

transaction_id๋Š” ํ•ด๋‹น ์„œ๋ฒ„์—์„œ ์ปค๋ฐ‹๋œ ํŠธ๋žœ์žญ์…˜์˜ ์ˆœ์„œ์— ๋”ฐ๋ผ ์ˆœ์ฐจ์ ์ธ ์ˆซ์ž๋กœ ๊ฒฐ์ •๋œ๋‹ค. ์˜ˆ๋กœ ์ฒซ ๋ฒˆ์งธ ํŠธ๋žœ์žญ์…˜์€ transaction_id=1์ด ๋˜๊ณ , ๋™์ผํ•œ ์„œ๋ฒ„์—์„œ ์—ด ๋ฒˆ์งธ ํŠธ๋žœ์žญ์…˜์€ transaction_id=10์ด ๋œ๋‹ค. (GTID์—์„œ ํŠธ๋žœ์žญ์…˜์ด ์ˆœ์ฐจ์ ์ธ ์ˆซ์ž๋Š” 1๋ถ€ํ„ฐ ์‹œ์ž‘๋œ๋‹ค. 0์€ ๋  ์ˆ˜ ์—†๋‹ค.)

๋ฐฑ์—…ํ•˜๊ธฐ

cr.yaml
backup:
  pitr:
    enabled: true
    storageName: s3-us-west-binlog
    timeBetweenUploads: 60
  storages:
    s3-us-west-fullbackup:
      type: s3
      s3:
        bucket: pxc-fullbackup
        credentialsSecret: backup-aws-s3
        region: us-west-1
    s3-us-west-binlog:
      type: s3
      s3:
        bucket: pxc-binlog
        credentialsSecret: backup-aws-s3
        region: us-west-1

full backup๊ณผ ๊ฐ™์ด pitr๋ฅผ ํ™œ์„ฑํ™” ํ•˜๊ณ  ์ ์šฉํ•˜์ž.

s3์— ํ™•์ธ์„ ํ•ด๋ณด๋ฉด ํŒŒ์ผ๋“ค์ด ๋ฐฑ์—…์ด ๋˜๊ณ  ์ž‡๋Š”๊ฒƒ์„ ์•Œ์ˆ˜ ์žˆ๋‹ค.

ํ™•์ธ

select @@global.gtid_executed; -- ํ˜„์žฌ GTID ํ™•์ธ
create database test;
select @@global.gtid_executed; -- GTID๊ฐ€ ์ฆ๊ฐ€ํ•œ๊ฒƒ์„ ๋ณผ์ˆ˜ ์žˆ๋‹ค.

60์ดˆ ๋’ค์—

์ƒˆ๋กœ์šด ํŒŒ์ผ์ด ์˜ฌ๋ผ์˜จ๊ฒƒ์„ ํ™•์ธํ• ์ˆ˜ ์žˆ๋‹ค.

๋‹ค์šด๋ฐ›์•„์„œ ํ™•์ธํ•ด๋ณด์ž.

mkdir log
#download s3
cd log
docker run --rm -v $(pwd):/binlog mysql:8 mysqlbinlog -v /binlog/binlog_1629743530_397451a8b1770fbc4ec2a983dfff161d

์ด๋ ‡๊ฒŒ ์ž‡๋Š”๋ฐ pxc์—์„œ row๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค. ๋กœ๊ทธ๋ฅผ ๋ณด๋ ค๋ฉด -v ์˜ต์…˜์„ ์ค˜์„œ ๋ด์•ผํ•œ๋‹ค.

๋ณต๊ตฌํ•˜๊ธฐ

restore.yaml
kind: PerconaXtraDBClusterRestore
metadata:
  name: restore1
spec:
  pxcCluster: cluster01
  backupName: backup1
  pitr:
    type: latest
    date: '2021-08-23 16:00:00'
    # gtid: "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee:nnn"
    # gtid: "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee:nnn-nnn,nnn-nnn"
    backupSource:
      storageName: 's3-us-west-binlog'
kubectl apply -f deploy/backup/restore.yaml
  • type

    • date - roll back to specific date,

    • transaction - roll back to specific transaction,

    • latest - recover to the latest possible transaction,

date๋ฅผ ์‚ฌ์šฉํ•ด์„œ ํŠน์ • ๋‚ ์งœ๋กœ ๋ณต๊ตฌ๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค.

gtid๋ฅผ ์ด์šฉํ•ด์„œ ํŠน์ • ์‹œํ€€์Šค๋„˜๋ฒ„ ๊นŒ์ง€ ๋ณต๊ตฌ๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค. ์˜ˆ๋ฅผ๋“ค๋ฉด '20' ๋งˆ์ง€๋ง‰ ๋ฒˆํ˜ธ ๋ฐ”๋กœ ์•ž๊นŒ์ง€๋งŒ ๋ณต๊ตฌ๋œ๋‹ค. 19๊นŒ์ง€ ๋ณต๊ตฌ๋œ๋‹ค.

gtid set๋ฅผ ์ด์šฉํ•ด์„œ '1-10,11-20' ์œผ๋กœ ๊ทธ๋ฃนํ™”ํ•˜์—ฌ ๋ณต๊ตฌ๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค. 9๋ฒˆ๊นŒ์ง€ ๋ณต๊ตฌํ•˜๊ณ  10๋ฒˆ์€ ๊ฑด๋„ˆ๋›ฐ๊ณ  11-20๋ฒˆ๊นŒ์ง€ ๋ณต๊ตฌ๋œ๋‹ค.

gtid๊ฐ’๋งŒ ์ฐพ์œผ๋ฉด ๋ณต๊ตฌ๊ฐ€ ์ด์ œ ๊ฐ€๋Šฅํ•˜๋‹ค.

create table movies(id int auto_increment primary key, name varchar(20) not null);
show tables;
insert into movies(name) values('hello1');
insert into movies(name) values('hello2');
insert into movies(name) values('hello3');
insert into movies(name) values('hello4');
insert into movies(name) values('hello5');
select * from movies;
delete from movies;
select * from movies;
insert into movies(name) values('new1');
insert into movies(name) values('new2');
insert into movies(name) values('new3');
insert into movies(name) values('new4');
insert into movies(name) values('new5');
select * from movies;

์ค‘๊ฐ„์— ๋‚ ๋ฆฐ delete๋งŒ ๋นผ๊ณ  ์‹ถ๋‹ค.

mkdir log
#download s3
cd log
docker run --rm -v $(pwd):/binlog -it mysql:8 mysqlbinlog -v /binlog/binlog_* | grep -i -e gtid_next -e delete

delete ์•ž์ชฝ์— ๋‚˜์˜ค๋Š” ๊ฐ’ 717์„ ์•Œ์•„๋‚ผ์ˆ˜ ์žˆ๋‹ค.

select @@global.gtid_executed; -- ํ˜„์žฌ GTID ํ™•์ธ 720

์ด์ œ ์ด๋ ‡๊ฒŒ ์ฒ˜๋ฆฌํ• ์ˆ˜ ์žˆ๋‹ค.

gtid: 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee:1-717,718-720'

์ด๋ ‡๊ฒŒ ๋ณต๊ตฌํ•˜๋ฉด๋œ๋‹ค.

point-in-time restore

์ด๊ฑธ ์œ„ํ•ด์„œ๋Š” bin log ํŒŒ์ผ์„ ๋ฐฑ์—…์„ ๋ฐ›์•„์•ผํ•œ๋‹ค.

์ด๋ถ€๋ถ„ ์ฃผ์„ ํ•ด์ œ ์Šคํ† ๋ฆฌ์ง€ ์ด๋ฆ„์„ ์ ์–ด์ฃผ๋ฉด bin logfile ๋ฅผ ์—…๋กœ๋“œํ•œ๋‹ค.

๋ณต๊ตฌ๋ฅผ ํ•ด๋ณด์ž.

vi reststore.yaml

Last updated