CockroachDB BACKUP/RECOVERY

https://www.cockroachlabs.com/docs/stable/backup-and-restore-overview

 

OS: Rocky Linux 9.2 
CockroachDB: v23.2.0

 

-- 1. テストデータ作成

cockroach sql \
--certs-dir=/cockroach/crc/certs \
--host=mmm191 \
-e "show databases;"


cockroach workload init movr postgresql://myuser:myuser@mmm191:26257?sslmode=require&sslcert=/cockroach/crc/certs/client.myuser.crt&sslkey=/cockroach/crc/certs/client.myuser.key&sslrootcert=/cockroach/crc/certs/ca.crt

cockroach workload run movr --duration 10s postgresql://myuser:myuser@mmm191:26257?sslmode=require&sslcert=/cockroach/crc/certs/client.myuser.crt&sslkey=/cockroach/crc/certs/client.myuser.key&sslrootcert=/cockroach/crc/certs/ca.crt \


cockroach workload init kv postgresql://myuser:myuser@mmm191:26257?sslmode=require&sslcert=/cockroach/crc/certs/client.myuser.crt&sslkey=/cockroach/crc/certs/client.myuser.key&sslrootcert=/cockroach/crc/certs/ca.crt

cockroach workload run kv --duration 10s postgresql://myuser:myuser@mmm191:26257?sslmode=require&sslcert=/cockroach/crc/certs/client.myuser.crt&sslkey=/cockroach/crc/certs/client.myuser.key&sslrootcert=/cockroach/crc/certs/ca.crt \

cockroach workload init bank postgresql://myuser:myuser@mmm191:26257?sslmode=require&sslcert=/cockroach/crc/certs/client.myuser.crt&sslkey=/cockroach/crc/certs/client.myuser.key&sslrootcert=/cockroach/crc/certs/ca.crt

cockroach workload run bank --duration 10s postgresql://myuser:myuser@mmm191:26257?sslmode=require&sslcert=/cockroach/crc/certs/client.myuser.crt&sslkey=/cockroach/crc/certs/client.myuser.key&sslrootcert=/cockroach/crc/certs/ca.crt \


cockroach sql \
--certs-dir=/cockroach/crc/certs \
--host=mmm191 \
-e "show databases;"

 

-- 2. フルバックアップ

※nodelocal://1/full.backupの"1"はノード番号

cockroach sql \
--certs-dir=/cockroach/crc/certs \
--host=mmm191 


BACKUP INTO 'nodelocal://1/full.backup/';

BACKUP INTO 'nodelocal://1/full.backup/' as of system time '2024-02-10 01:15:00+00';

show backups in 'nodelocal://1/full.backup/';

 

-- 3. データベースバックアップ

BACKUP database movr INTO 'nodelocal://1/movr.backup/';

BACKUP database movr INTO 'nodelocal://1/movr.backup/' as of system time '2024-02-10 01:15:00+00';

show backups in 'nodelocal://1/movr.backup/';

 

-- 4. フルリストア

use system;

show databases;

show databases;
drop database bank CASCADE;
drop database kv CASCADE;
drop database movr CASCADE;
drop database postgres CASCADE;
drop database test CASCADE;
drop database defaultdb CASCADE;

show databases;


show backups in 'nodelocal://1/full.backup/';

RESTORE FROM '2024/02/10-011500.00' IN 'nodelocal://1/full.backup/';

show databases;

 


-- 5. データベースリストア

use system;
show databases;
drop database movr CASCADE;
show databases;

show backups in 'nodelocal://1/movr.backup/';


RESTORE database movr FROM '2024/02/10-011500.00' IN 'nodelocal://1/movr.backup/';

RESTORE database movr FROM '2024/02/10-011500.00' IN 'nodelocal://1/movr.backup/' WITH new_db_name = 'movr2';


show databases;