©2015 - 2022 Chad’s Technoworks. Disclaimer and Terms of Use

Chad’s TechnoWorks My Journal On Technology

Information Technology

COUCHBASE BACKUP AND RECOVERY - page 2

 Prev< 1 2

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 - Restoring with cbrestore.


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' -U http://lxnode5.vlabs.net

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-f9e0-48bb-aa78-e1abf6de6c68",

    "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-delete -U http://lxnode5.vlabs.net -u Administrator -P mypass CRUD_Lab

Requesting /pools/default/buckets/CRUD_Lab

200

  Cache-Control: no-cache

  Content-Length: 0

  Date: Fri, 11 Mar 2016 21:30:46 GMT

  Pragma: no-cache

  Server: Couchbase Server

[couchbas@lxnode4 ~]$



[couchbas@lxnode4 ~]$ cbc n1ql 'SELECT * from CRUD_Lab' -U http://lxnode5.vlabs.net

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-41b6-4c52-944c-35fa471dd383",

    "errors": [

        {

            "code": 12003,

            "msg": "Keyspace not found keyspace CRUD_Lab - cause: No bucket named 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-create --bucket-type=couchbase --ram-quota=100 \

> -u Administrator -P - -U http://lxnode5.vlabs.net CRUD_Lab

Requesting /pools/default/buckets

Bucket password:

202

  Cache-Control: no-cache

  Content-Length: 0

  Date: Fri, 11 Mar 2016 22:01:13 GMT

  Location: /pools/default/buckets/CRUD_Lab

  Pragma: no-cache

  Server: Couchbase Server

[couchbas@lxnode4 ~]$




3. Perform a restore onto the empty bucket.


List the available buckets in the backup dir:


[couchbas@lxnode5 2016-03-02T214418Z-full]$ pwd

/app/couchbase/inst1/backup/current/2016-03-02T214418Z/2016-03-02T214418Z-full

[couchbas@lxnode5 2016-03-02T214418Z-full]$ ls -l

total 20

drwxr-xr-x. 4 couchbas nosql 4096 Mar  2 15:44 bucket-CRUD_Lab

drwxr-xr-x. 2 couchbas nosql 4096 Mar  2 15:44 bucket-default

drwxr-xr-x. 3 couchbas nosql 4096 Mar  2 15:44 bucket-sync_gateway

drwxr-xr-x. 4 couchbas nosql 4096 Mar  2 15:44 bucket-syncGW_CRUD_Lab

drwxr-xr-x. 4 couchbas nosql 4096 Mar  2 15:44 bucket-travel-sample-dc2

[couchbas@lxnode5 2016-03-02T214418Z-full]$



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 \

> --bucket-source=CRUB_lab

error: missing bucket-destination: CRUB_lab at destination: http://Administrator:mypass@lxnode5.vlabs.net:8091; perhaps your username/password is missing or incorrect

[couchbas@lxnode5 ~]$



Execute the restore of the CRUD_Lab bucket


[couchbas@lxnode5 ~]$ cbrestore -u Administrator -p mypass /app/couchbase/inst1/backup/current \

> http://lxnode5.vlabs.net:8091 -b CRUD_Lab

  [####################] 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' -U http://lxnode5.vlabs.net

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-7e0c-41d0-b296-58b4ed6d3256",

    "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`' -U http://lxnode5cb-vip.vlabs.net

Encoded query: {"statement":"CREATE PRIMARY INDEX ON `CRUD_Lab`"}


** N1QL Response finished

{

    "requestID": "ec4e6eb4-fdc4-440b-a34b-81745296e9f5",

    "signature": null,

    "results": [

    ],

    "errors": [

        {

            "code": 5000,

            "msg": "GSI CreatePrimaryIndex() - cause: Index #primary already exist."

        }

    ],

    "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`' -U http://lxnode5cb-vip.vlabs.net

Encoded query: {"statement":"drop primary index on `CRUD_Lab`"}


** N1QL Response finished

{

    "requestID": "69fa106b-93db-4b25-8927-d864edc01966",

    "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`' -U http://lxnode5cb-vip.vlabs.net

Encoded query: {"statement":"CREATE PRIMARY INDEX ON `CRUD_Lab`"}


** N1QL Response finished

{

    "requestID": "b50e9dca-bcaf-40af-84b2-8638c31c6285",

    "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;' -U http://lxnode5cb-vip.vlabs.net

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-7a47-4b64-9ef7-4addc1dcba18",

    "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' -U http://lxnode5.vlabs.net

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-5280-49a3-a3aa-45dc2bdb4aad",

    "signature": {

        "*": "*"

    },

    "results": [

        ],

    "status": "success",

    "metrics": {

        "elapsedTime": "32.553523ms",

        "executionTime": "32.400392ms",

        "resultCount": 5,

        "resultSize": 2154

    }

}


[couchbas@lxnode4 ~]$