©2015 -
COUCHBASE BACKUP AND RECOVERY -
COUCHBASE RESTORE
Couchbase allows us to restore the backup data onto any cluster. The restore process is done one bucket at a time with option for data filtering. This gives you flexibility to choose selectively the namespace to restore and the kind of data. You can also restore onto a different bucket name. The restore process implements data streaming just like any other transaction against a cluster. But one has to manually rebuild the index and views (if there were any) after the restore process.
You need to use cbrestore utility to perform data restore of a backup done by cbbackup. Additional information related to the syntax and options are found in Couchbase CLI Reference Documentation of cbrestore. Concepts related to restore process are found in the Administration documentation -
In this exercise, we will demonstrate a restore of a dropped bucket to simulate a data refresh of a development environment using the backups.
RESTORE DEMO
This demo will perform the restore of a CRUD_Lab bucket which undergoes the following process:
1. Check the contents of the existing data of CRUD_Lab which we will use as our point of reference to compare the restored data later on.
2. Drop the CRUD_Lab bucket and create the equivalent empty bucket.
3. Perform a restore onto the empty bucket.
4. Perform a reindex.
5. Run a query against the restored bucket to check the contents of the data restored.
Note that I am using the cbc utility to perform the CRUD commands at lxnode4, while restore procedures are being done in one of the cluster nodes (lxnode5).
Let’s begin:
1. Check the contents of the existing data of CRUD_Lab which we will use as our point of reference to compare the restored data later on.
[couchbas@lxnode4 ~]$ cbc n1ql 'SELECT * from CRUD_Lab' -
Encoded query: {"statement":"SELECT * from CRUD_Lab"}
{
"CRUD_Lab": {
"comm": 0,
"dept": {
"deptno": 20,
"dname": "RESEARCH",
"loc": "DALLAS"
},
"empno": 1234,
"ename": "KYLE",
"hiredate": "1989/10/15",
"job": "MUPPET",
"mgr": 7902,
"sal": 900
}
},
{
"CRUD_Lab": {
"comm": 100,
"dept": {
"deptno": 30,
"dname": "SALES",
"loc": "CHICAGO"
},
"empno": 6789,
"ename": "PEDRO",
"hiredate": "1982/07/10",
"job": "SALESMAN",
"mgr": 7698,
"sal": 1500
}
},
{
"CRUD_Lab": {
"comm": 0,
"dept": {
"deptno": 20,
"dname": "RESEARCH",
"loc": "DALLAS"
},
"empno": 7369,
"ename": "SMITH",
"hiredate": "1980/12/17",
"job": "CLERK",
"mgr": 7902,
"sal": 800
}
},
{
"CRUD_Lab": {
"comm": 300,
"dept": {
"deptno": 30,
"dname": "SALES",
"loc": "CHICAGO"
},
"empno": 7499,
"ename": "ALLEN",
"hiredate": "1981/02/20",
"job": "SALESMAN",
"mgr": 7698,
"sal": 1600
}
},
{
"CRUD_Lab": {
"comm": 0,
"dept": {
"deptno": 30,
"dname": "SALES",
"loc": "CHICAGO"
},
"empno": 7698,
"ename": "BLAKE",
"hiredate": "1981/05/01",
"job": "MANAGER",
"mgr": 7839,
"sal": 2850
}
},
** N1QL Response finished
{
"requestID": "23b6b747-
"signature": {
"*": "*"
},
"results": [
],
"status": "success",
"metrics": {
"elapsedTime": "220.240622ms",
"executionTime": "213.656933ms",
"resultCount": 5,
"resultSize": 2154
}
}
[couchbas@lxnode4 ~]$
2. Drop the CRUD_Lab bucket and create the equivalent empty bucket. This would simulate a new cluster with an empty bucket.
[couchbas@lxnode4 ~]$ cbc bucket-
Requesting /pools/default/buckets/CRUD_Lab
200
Cache-
Content-
Date: Fri, 11 Mar 2016 21:30:46 GMT
Pragma: no-
Server: Couchbase Server
[couchbas@lxnode4 ~]$
[couchbas@lxnode4 ~]$ cbc n1ql 'SELECT * from CRUD_Lab' -
Encoded query: {"statement":"SELECT * from CRUD_Lab"}
** N1QL Response finished
N1QL query failed with library code 0x3b
Inner HTTP request failed with library code 0x0 and HTTP status 500
{
"requestID": "eec466ea-
"errors": [
{
"code": 12003,
"msg": "Keyspace not found keyspace CRUD_Lab -
}
],
"status": "fatal",
"metrics": {
"elapsedTime": "61.641066ms",
"executionTime": "61.474333ms",
"resultCount": 0,
"resultSize": 0,
"errorCount": 1
}
}
[couchbas@lxnode4 ~]$
Create destination bucket:
[couchbas@lxnode4 ~]$ cbc bucket-
> -
Requesting /pools/default/buckets
Bucket password:
202
Cache-
Content-
Date: Fri, 11 Mar 2016 22:01:13 GMT
Location: /pools/default/buckets/CRUD_Lab
Pragma: no-
Server: Couchbase Server
[couchbas@lxnode4 ~]$
3. Perform a restore onto the empty bucket.
List the available buckets in the backup dir:
[couchbas@lxnode5 2016-
/app/couchbase/inst1/backup/current/2016-
[couchbas@lxnode5 2016-
total 20
drwxr-
drwxr-
drwxr-
drwxr-
drwxr-
[couchbas@lxnode5 2016-
Make sure that a destination bucket is created, otherwise, you'll get an error similar to this when doing a restore:
[couchbas@lxnode5 ~]$ cbrestore /app/couchbase/inst1/backup/current http://Administrator:mypass@lxnode5.vlabs.net:8091 \
> -
error: missing bucket-
[couchbas@lxnode5 ~]$
Execute the restore of the CRUD_Lab bucket
[couchbas@lxnode5 ~]$ cbrestore -
> http://lxnode5.vlabs.net:8091 -
[####################] 100.0% (5/estimated 5 msgs)
bucket: CRUD_Lab, msgs transferred...
: total | last | per sec
byte : 851 | 851 | 10098.1
done
[couchbas@lxnode5 ~]$
4. Rebuild primary index so N1QL statements can be performed.
[couchbas@lxnode4 ~]$ cbc n1ql 'SELECT * from CRUD_Lab' -
Encoded query: {"statement":"SELECT * from CRUD_Lab"}
** N1QL Response finished
N1QL query failed with library code 0x3b
Inner HTTP request failed with library code 0x0 and HTTP status 404
{
"requestID": "2b2bd9ce-
"errors": [
{
"code": 4000,
"msg": "Primary index #primary not online."
}
],
"status": "fatal",
"metrics": {
"elapsedTime": "55.417176ms",
"executionTime": "55.25572ms",
"resultCount": 0,
"resultSize": 0,
"errorCount": 1
}
}
[couchbas@lxnode4 ~]$
[couchbas@lxnode4 ~]$ cbc n1ql 'CREATE PRIMARY INDEX ON `CRUD_Lab`' -
Encoded query: {"statement":"CREATE PRIMARY INDEX ON `CRUD_Lab`"}
** N1QL Response finished
{
"requestID": "ec4e6eb4-
"signature": null,
"results": [
],
"errors": [
{
"code": 5000,
"msg": "GSI CreatePrimaryIndex() -
}
],
"status": "errors",
"metrics": {
"elapsedTime": "10.692202ms",
"executionTime": "10.627902ms",
"resultCount": 0,
"resultSize": 0,
"errorCount": 1
}
}
[couchbas@lxnode4 ~]$
[couchbas@lxnode4 ~]$ cbc n1ql 'drop primary index on `CRUD_Lab`' -
Encoded query: {"statement":"drop primary index on `CRUD_Lab`"}
** N1QL Response finished
{
"requestID": "69fa106b-
"signature": null,
"results": [
],
"status": "success",
"metrics": {
"elapsedTime": "14.297476ms",
"executionTime": "14.232434ms",
"resultCount": 0,
"resultSize": 0
}
}
[couchbas@lxnode4 ~]$
[couchbas@lxnode4 ~]$ cbc n1ql 'CREATE PRIMARY INDEX ON `CRUD_Lab`' -
Encoded query: {"statement":"CREATE PRIMARY INDEX ON `CRUD_Lab`"}
** N1QL Response finished
{
"requestID": "b50e9dca-
"signature": null,
"results": [
],
"status": "success",
"metrics": {
"elapsedTime": "3.67379555s",
"executionTime": "3.673641545s",
"resultCount": 0,
"resultSize": 0
}
}
[couchbas@lxnode4 ~]$
[couchbas@lxnode4 ~]$ cbc n1ql 'SELECT * FROM system:indexes;' -
Encoded query: {"statement":"SELECT * FROM system:indexes;"}
{
"indexes": {
"datastore_id": "http://127.0.0.1:8091",
"id": "56ac89796acae6c8",
"index_key": [],
"is_primary": true,
"keyspace_id": "CRUD_Lab",
"name": "#primary",
"namespace_id": "default",
"state": "online",
"using": "gsi"
}
},
** N1QL Response finished
{
"requestID": "0c6495f0-
"signature": {
"*": "*"
},
"results": [
],
"status": "success",
"metrics": {
"elapsedTime": "163.004078ms",
"executionTime": "162.909399ms",
"resultCount": 1,
"resultSize": 406
}
}
[couchbas@lxnode4 ~]$
5. Run a query against the restored bucket to check the contents of the data restored.
[couchbas@lxnode4 ~]$ cbc n1ql 'SELECT * from CRUD_Lab' -
Encoded query: {"statement":"SELECT * from CRUD_Lab"}
{
"CRUD_Lab": {
"comm": 0,
"dept": {
"deptno": 20,
"dname": "RESEARCH",
"loc": "DALLAS"
},
"empno": 1234,
"ename": "KYLE",
"hiredate": "1989/10/15",
"job": "MUPPET",
"mgr": 7902,
"sal": 900
}
},
{
"CRUD_Lab": {
"comm": 100,
"dept": {
"deptno": 30,
"dname": "SALES",
"loc": "CHICAGO"
},
"empno": 6789,
"ename": "PEDRO",
"hiredate": "1982/07/10",
"job": "SALESMAN",
"mgr": 7698,
"sal": 1500
}
},
{
"CRUD_Lab": {
"comm": 0,
"dept": {
"deptno": 20,
"dname": "RESEARCH",
"loc": "DALLAS"
},
"empno": 7369,
"ename": "SMITH",
"hiredate": "1980/12/17",
"job": "CLERK",
"mgr": 7902,
"sal": 800
}
},
{
"CRUD_Lab": {
"comm": 300,
"dept": {
"deptno": 30,
"dname": "SALES",
"loc": "CHICAGO"
},
"empno": 7499,
"ename": "ALLEN",
"hiredate": "1981/02/20",
"job": "SALESMAN",
"mgr": 7698,
"sal": 1600
}
},
{
"CRUD_Lab": {
"comm": 0,
"dept": {
"deptno": 30,
"dname": "SALES",
"loc": "CHICAGO"
},
"empno": 7698,
"ename": "BLAKE",
"hiredate": "1981/05/01",
"job": "MANAGER",
"mgr": 7839,
"sal": 2850
}
},
** N1QL Response finished
{
"requestID": "efabd06c-
"signature": {
"*": "*"
},
"results": [
],
"status": "success",
"metrics": {
"elapsedTime": "32.553523ms",
"executionTime": "32.400392ms",
"resultCount": 5,
"resultSize": 2154
}
}
[couchbas@lxnode4 ~]$