Cassandra Backup and Restore

백업 복구 테스트를 위한 시나리오 설명

“demo”라는 이름의 keyspace에 몇 건의 데이터를 포함한 “demo_table”라는 Table이 존재하고 이를 백업하고 복구하는 테스트를 진행해보자

백업 복구 환경 만들기

# demo keyspace 생성
cqlsh> CREATE KEYSPACE demo WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 3};
# demo_table 생성 및 데이터 입력
cqlsh> USE demo;
cqlsh:demo> CREATE TABLE demo_table ( name text PRIMARY KEY );
cqlsh:demo> SELECT * from demo_table ;
 name
------
(0 rows)
cqlsh:demo> INSERT INTO demo_table ( name ) VALUES ( 'Kim' );
cqlsh:demo> INSERT INTO demo_table ( name ) VALUES ( 'Lee' );
cqlsh:demo> INSERT INTO demo_table ( name ) VALUES ( 'Park' );
cqlsh:demo> SELECT * FROM demo_table ;
 name
------
 Park
  Kim
  Lee
(3 rows)
cqlsh:demo> exit

위와 같이 demo라는 keyspace에 3건의 데이터가 존재하는 demo_table이 있다고 가정한다.

Backup

백업은 cassandrasnapshot을 이용한다.

snapshot 생성

Note : nodetool 명령어를 이용해 demo keyspace의 snapshot 생성

[root@cassandra-node0 ~]# nodetool -h localhost snapshot demo
Requested creating snapshot(s) for [demo] with snapshot name [1461038839227]
Snapshot directory: 1461038839227
[root@cassandra-node0 ~]#

생성된 snapshot 확인

아래의 결과와 같이 /var/lib/cassandra/data/demo/demo_table-7883fdd005e311e68ccc67c7ac5bfa1e/snapshots/ 디렉토리 내에 생성된 snapshot 파일을 확인 할 수 있다.

[root@cassandra-node0 ~]# tree /var/lib/cassandra/data/demo/demo_table-7883fdd005e311e68ccc67c7ac5bfa1e/snapshots/1461038839227/
/var/lib/cassandra/data/demo/demo_table-7883fdd005e311e68ccc67c7ac5bfa1e/snapshots/1461038839227/
├── ma-1-big-CompressionInfo.db
├── ma-1-big-Data.db
├── ma-1-big-Digest.crc32
├── ma-1-big-Filter.db
├── ma-1-big-Index.db
├── ma-1-big-Statistics.db
├── ma-1-big-Summary.db
├── ma-1-big-TOC.txt
└── manifest.json
0 directories, 9 files

Restore

복구 테스트를 위한 준비

앞에서 만든 demo keyspace가 어떠한 이유에서 건 유실이 된 상황을 만들기 위해 demo keyspace를 지워보도록 하겠다.

[root@cassandra-node0 ~]# cqlsh
Connected to MyCassandraCluster at 127.0.0.1:9042.
[cqlsh 5.0.1 | Cassandra 3.0.4 | CQL spec 3.4.0 | Native protocol v4]
Use HELP for help.
cqlsh> DROP KEYSPACE demo ;
OperationTimedOut: errors={}, last_host=127.0.0.1
cqlsh> DESC KEYSPACES ;
system_traces  system_schema  system_auth  system  system_distributed
cqlsh>

keyspace, table 생성

cqlsh> CREATE KEYSPACE demo WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 3};
cqlsh> use demo ;
cqlsh:demo> CREATE TABLE demo_table ( name text PRIMARY KEY );
cqlsh:demo> select * from demo_table;
 name
------
(0 rows)
cqlsh:demo>

snapshot 파일 복사

/var/lib/cassandra/data/demo 경로에 보면 demo_table-xxxxxxxxxxxxxxxx...형태의 디렉토리가 두개 보이는데 그 중에 빈 디렉토리가 방금전 새로 만든 테이블이고 backup,snapshot 디렉토리가 들어가 있는 디렉토리는 위에서 삭제한 table이다.
아래 내용에서 보면 demo_table-083e21e005e811e68ccc67c7ac5bfa1e이 새로 생성한 테이블이니 snapshot 들어있는 demo_table-7883fdd005e311e68ccc67c7ac5bfa1e내에 있는 snapshot 파일을 demo_table-083e21e005e811e68ccc67c7ac5bfa1e 으로 복사한다.

# 새로만든 demo의 디렉토리 구조
[root@cassandra-node0 ~]# tree /var/lib/cassandra/data/demo/demo_table-*
/var/lib/cassandra/data/demo/demo_table-083e21e005e811e68ccc67c7ac5bfa1e
└── backups
/var/lib/cassandra/data/demo/demo_table-7883fdd005e311e68ccc67c7ac5bfa1e
├── backups
└── snapshots
    ├── 1461038839227
    │   ├── ma-1-big-CompressionInfo.db
    │   ├── ma-1-big-Data.db
    │   ├── ma-1-big-Digest.crc32
    │   ├── ma-1-big-Filter.db
    │   ├── ma-1-big-Index.db
    │   ├── ma-1-big-Statistics.db
    │   ├── ma-1-big-Summary.db
    │   ├── ma-1-big-TOC.txt
    │   └── manifest.json
    └── 1461039754137-demo_table
        ├── ma-1-big-CompressionInfo.db
        ├── ma-1-big-Data.db
        ├── ma-1-big-Digest.crc32
        ├── ma-1-big-Filter.db
        ├── ma-1-big-Index.db
        ├── ma-1-big-Statistics.db
        ├── ma-1-big-Summary.db
        ├── ma-1-big-TOC.txt
        └── manifest.json
5 directories, 18 files
# snapshot 파일 복사
[root@cassandra-node0 ~]# cp /var/lib/cassandra/data/demo/demo_table-7883fdd005e311e68ccc67c7ac5bfa1e/snapshots/1461038839227/* /var/lib/cassandra/data/demo/demo_table-083e21e005e811e68ccc67c7ac5bfa1e811e68ccc67c7ac5bfa1e/
[root@cassandra-node0 ~]# ls /var/lib/cassandra/data/demo/demo_table-083e21e005e811e68ccc67c7ac5bfa1e/
backups                      ma-1-big-Data.db       ma-1-big-Filter.db  ma-1-big-Statistics.db  ma-1-big-TOC.txt
ma-1-big-CompressionInfo.db  ma-1-big-Digest.crc32  ma-1-big-Index.db   ma-1-big-Summary.db     manifest.json
[root@cassandra-node0 ~]#

새로운 데이터를 로드

[root@cassandra-node0 ~]# nodetool refresh demo demo_table

데이터 확인

cqlsh> use demo ;
cqlsh:demo> select * from demo_table;
 name
------
 Park
  Kim
  Lee
(3 rows)
cqlsh:demo>

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다