Jeffrey
Jeffrey

Reputation: 4506

How to recover couchbase to the status of a backup?

I use cbbackup to backup couchbase. Then do some operations to the db, like adding and deleting documents. After the operation, I want to discard all the operations and recover db to the status of the backup.

I did the following test. cbbackup and cbrestore don't help during my test. How to achieve my goal?

  1. Backup db

    $ rm -rf /tmp/cbbackup
    $ /opt/couchbase/bin/cbbackup http://cb_ip:8091  /tmp/cbbackup -u 'xxx' -p '***' -v
    
  2. Remember the item count of the social bucket.

    • Count: 33
  3. Delete one document from social bucket
    • Delete id: existing-item-110
  4. Add two new document to social bucket
    • Ids: new-item-1, new-item-2
  5. Remember the item count of the social bucket.
    • Count: 34
  6. Restore social bucket

    $ /opt/couchbase/bin/cbrestore /tmp/cbbackup http://cb_ip:8091 -u 'xxx' -p '***' -b mybucket -v
    
  7. Verify if the deleted document is back and if the added documents are removed.

    • Result: Count: 34, no change
    • The deleted item is not back.
    • The added items are not deleted.
  8. Conclution: cbrestore can't recover the db to a backup time point. The changes after the backup time point are not removed.

  9. Use cbtransfer to restore data. The result and conclusion is the same as cbrestore.

    $ /opt/couchbase/bin/cbtransfer /tmp/cbbackup http://cb_ip:8091 -u 'xxx' -p '***' -b mybucket -v
    

Upvotes: 2

Views: 1193

Answers (1)

mikewied
mikewied

Reputation: 5343

Before I directly answer you're question let me explain two important concepts about cbbackup and cbrestore.

  1. These tools do not transfer raw data files during the backup and restore process. During backup data is streamed out of the server and written to disk and during restore data is put into the database using set operations.

  2. Couchbase has the ability to do conflict resolution during sets. This means that if you backed up a key, then updated it, then do a restore and conflict resolution is enabled then the set during the restore will be discarded since it is not the latest update.

Below are two backup scenarios that are applicable to your use case.

First let's take a look at the point-in-time restore scenario. In order to achieve this you should delete and recreate your bucket and then run cbrestore. The reason is that cbrestore will not be aware of new keys you have added after the backup and will not be able to delete them.

Let's say in another scenario you just want to force overwrite all of the data in your bucket with the data you backed up. In this case you want to disable conflict resolution and you can do this with the "-x conflict_resolve=0" flag. This would work in a case when I backed up 1000 keys, then updated them, and then wanted to revert the updates I did after the backup. (Note that the conflict_resolve flag was accidentally removed in Couchbase 4.0 and 4.1, but will be added back in 4.1.1 and 4.5)

On a final note, I would recommend against using cbtranfer since it is not tested as well as cbbackup and cbrestore and that tool is generally only used as a last resort.

Upvotes: 3

Related Questions