Module 6 - Backup and Restore ONLY a specific set of documents, Backup and Restore a Bucket, Backup and Restore Entire Couchbase Cluster

  cbbackupmgr – Configure a backup :  

cbbackupmgr config -a /data/bkp -r cluster

cbbackupmgr config -a /data/bkp -r single --include-buckets travel-sample

  cbbackupmgr – list the backups:  

cbbackupmgr list --archive /data/bkp

cbbackupmgr list -a /tmp/bkp -r single

cbbackupmgr list -a /tmp/bkp -r cluster \
--backup 2020-12-23T01_24_01.3433522434-03_00 --bucket travel-sample

  Create Entire Cluster Backup:  

/opt/couchbase/bin/cbbackupmgr config --archive /backup --repo repo1    (You can exclude (or) include buckets here)

/opt/couchbase/bin/cbbackupmgr backup --archive /backup --repo repo1 --cluster couchbase://10.128.0.2 -u Administrator -p couchbase --threads 4       

  Check Backup:  

/opt/couchbase/bin/cbbackupmgr info --archive /backup --repo repo1

/opt/couchbase/bin/cbbackupmgr list --archive /backup --repo repo1

  Copy Files Between GCP Nodes:  

Copy from source cluster to bucket:

gsutil cp backup.tar gs://couchbase-bucket/

Copy from bucket to Target cluster:
gsutil cp gs://couchbase-bucket/backup.tar /tmp

  Restore:  


All Buckets:

/opt/couchbase/bin/cbbackupmgr config --archive /restore --repo repo2

/opt/couchbase/bin/cbbackupmgr restore --archive /restore --repo repo2 --cluster couchbase://10.128.0.4 -u Administrator -p couchbase --threads 4
        Exclude One Buckets: while Restoring

/opt/couchbase/bin/cbbackupmgr restore --archive /restore --repo repo2 --cluster couchbase://10.128.0.4 -u Administrator -p couchbase --threads 4 --exclude-buckets 'travel-sample'
Exclude Two Buckets: while Restoring

/opt/couchbase/bin/cbbackupmgr restore --archive /restore --repo repo2 --cluster couchbase://10.128.0.4 -u Administrator -p couchbase --threads 4 --exclude-buckets 'travel-sample,REST-TMP'
If the backup fails?

/opt/couchbase/bin/cbbackupmgr backup -a /data/bkp -r example -c `hostname` -u Administrator -p password --resume

[OR]

/opt/couchbase/bin/cbbackupmgr backup -a /data/bkp -r example -c `hostname` -u Administrator -p password --purge

  cbbackupmgr – restore  (to specific backup with --end tag)

/opt/couchbase/bin/cbbackupmgr restore -a /tmp/bkp -r cluster \
-c http://127.0.0.1:8091 -u Administrator -p password \
--start 2020-12-24T23_00_16.14337588-07_00 \
--end 2020-12-24T23_00_17.14337588-07_00
##with FORCE - Force overwrite key-value pairs being restored even if  the key-value pair on the cluster is newer than the one being  restored
/opt/couchbase/bin/cbbackupmgr restore -a /tmp/bkp -r cluster \
-c http://127.0.0.1:8091 -u Administrator -p password \
--start 2020-12-24T23_00_16.14337588-07_00 \
--end 2020-12-24T23_00_17.14337588-07_00 --force-updates

  cbbackupmgr merge:  

/opt/couchbase/bin/cbbackupmgr merge -a /tmp/test-bkp -r test-repo --start 2021-11-14T10_15_40.773826573Z --end 2021-11-14T10_20_19.540516006Z

  cbbackupmgr remove:  

/opt/couchbase/bin/cbbackupmgr remove -a /tmp/test-bkp -r test-repo

  Backing Up a Cluster(Cloud):  

/opt/couchbase/bin/cbbackupmgr backup -a s3://bucket/arch -r repo
--obj-staging-dir /mnt/staging
-c http://192.168.0.100:8091 -u Administrator -p password

  Restore a Cluster(Cloud):  

/opt/couchbase/bin/cbbackupmgr restore -a s3://bucket/arch -r repo
--obj-staging-dir /mnt/staging \
-c http://192.168.0.100:8091 -u Administrator -p password

  Backup and restore ONLY specific set of documents like 'rep':  

Get count from GUI (query tab) :

select meta().id from `travel-sample` where meta().id like '%rep%';

[OR]

select count(*) from `travel-sample` where meta().id like '%rep%';

/opt/couchbase/bin/cbbackup http://10.128.0.2:8091 /tmp/rest-bkp -u Administrator -p 'couchbase' -b travel-sample -k '^rep*'

Crosscheck Cluster & Bucket Name:

/opt/couchbase/bin/cbrestore /tmp/rest-bkp http://10.128.0.2:8091/ -u Administrator -p 'couchbase' --bucket-source=travel-sample --bucket-destination=rep-bucket

  Restore specific keys/single document using cbbackupmgr:  

/opt/couchbase/bin/cbbackupmgr config -a /tmp/cbbackupmgr-bkp -r single --include-buckets travel-sample
 

/opt/couchbase/bin/cbbackupmgr backup --archive
/tmp/cbbackupmgr-bkp --repo single --cluster couchbase://10.128.0.2 -u Administrator -p 'couchbase'


/opt/couchbase/bin/cbbackupmgr list --archive /tmp/cbbackupmgr-bkp --repo single

/opt/couchbase/bin/cbbackupmgr restore -a /tmp/cbbackupmgr-bkp -r single \
 -c couchbase://127.0.0.1 -u Administrator -p couchbase \
 --start 2021-06-22T02_15_05.538818553Z \
 --end 2021-06-23T02_15_04.47314733Z \
 --filter-keys '^test*' \
 --exclude-buckets "REST-TMP,REST"
 --map-buckets "travel-sample=rep-bucket"

[OR]

/opt/couchbase/bin/cbbackupmgr restore -c http://34.130.100.164:8091 -u Administrator -p couchbase \
 -a /tmp/cbbackupmgr-bkp -r single --map-buckets "travel-sample=rep-bucket" --filter-keys '^rep*'

  Backup and restore a bucket using cbbackup & cbrestore:  

//BACKUP
/opt/couchbase/bin/cbbackup http://`hostname`:8091 /tmp/rest-bkp2 -u Administrator -p 'couchbase' -b REST --threads=2

//RESTORE
/opt/couchbase/bin/cbrestore /tmp/rest-bkp2 http://`hostname`:8091 --bucket-source=REST --bucket-destination=REST-TMP -u Administrator -p 'couchbase' -x conflict_resolve=0 --threads=4

/opt/couchbase/bin/cbrestore /tmp/rest-bkp2 http://`hostname`:8091 --bucket-source=REST --bucket-destination=rep-bucket -u Administrator -p 'couchbase' -x conflict_resolve=0 --threads=4

//to force all data to be copied/restored to couchbase
cbrestore -x conflict_resolve=0

  Backup and restore a bucket using cbbackupmgr:  

#Create repo1 in archive:/tmp/travelsample-bkp
/opt/couchbase/bin/cbbackupmgr config --archive /tmp/travelsample-bkp --repo repo1 --include-buckets travel-sample

#Take backup
/opt/couchbase/bin/cbbackupmgr backup --archive /tmp/travelsample-bkp --repo repo1 -host couchbase://`hostname` --username Administrator --password 'couchbase' --threads 2

#Restore backup
/opt/couchbase/bin/cbbackupmgr restore -c http://35.238.107.22:8091 -u Administrator -p couchbase \
-a /tmp/travelsample-bkp -r repo1 --map-buckets "travel-sample=rep-bucket"

//--force-updates -If you want to restore a backup to a bucket with a different conflict resolution type, you can do that by using the --force-updates

#Restore backup with force-updates
/opt/couchbase/bin/cbbackupmgr restore -c http://35.238.107.22:8091 -u Administrator -p couchbase \
-a /tmp/travelsample-bkp -r repo1 --map-buckets "travel-sample=REST-TMP" --force-updates

  Command to get the index definition of all indexes present in cluster:  

curl -X GET http://`hostname`:8091/indexStatus -u Administrator |python -mjson.tool|grep -i "definition"

[OR]

curl --user Administrator:couchbase --silent --connect-timeout 5 --request GET --write-out 'HTTPSTATUS:%{http_code}' http://`hostname`:8091/indexStatus|sed 's/"definition"/\n"/g;s/":"CREATE/CREATE/g;s/","status"/\n"/g'|grep -w CREATE

  Command to take bucket password backup:  

curl -X GET -j -u "Administrator:couchbase" http://`hostname`:8091/pools/default/buckets/REST | egrep -i saslPassword >bucket_password.txt

  Couchbase Single/Binary document Backup:  

/opt/couchbase/bin/cbbackup http://`hostname`:8091 /tmp -u Administrator -p 'couchbase' -b  REST -k 'bindoc' -t 2

  Couchbase Single/Binary document Restore

/opt/couchbase/bin/cbrestore /tmp/ http://`hostname`:8091/ -u Administrator -p 'couchbase' --bucket-source=REST --bucket-destination=REST-TMP -t 2

 Single/Binary document Backup & Restore using cbbackupmgr:  

/opt/couchbase/bin/cbbackupmgr config -a /tmp/cbbackupmgr-bkp -r single --include-buckets travel-sample  

/opt/couchbase/bin/cbbackupmgr backup --archive /tmp/cbbackupmgr-bkp --repo single --cluster couchbase://10.128.0.2 -u Administrator -p 'couchbase'

/opt/couchbase/bin/cbbackupmgr list --archive /tmp/cbbackupmgr-bkp --repo single

/opt/couchbase/bin/cbbackupmgr restore -a /tmp/cbbackupmgr-bkp -r single \
 -c couchbase://127.0.0.1 -u Administrator -p couchbase \
 --start 2021-06-22T02_15_05.538818553Z \
 --end 2021-06-23T02_15_04.47314733Z \
 --filter-keys 'binary-doc-name' \
 --exclude-buckets "REST-TMP,REST"
 --map-buckets "travel-sample=rep-bucket"

[OR]

/opt/couchbase/bin/cbbackupmgr restore -c http://34.130.100.164:8091 -u Administrator -p couchbase \
 -a /tmp/cbbackupmgr-bkp -r single --map-buckets "travel-sample=rep-bucket" --filter-keys 'binary-doc-name'


 Backup & Restore Entire Couchbase Cluster 

  Create Entire Cluster Backup:  

/opt/couchbase/bin/cbbackupmgr config --archive /backup --repo repo1    (You can exclude (or) include buckets here)

/opt/couchbase/bin/cbbackupmgr backup --archive /backup --repo repo1 --cluster couchbase://10.128.0.2 -u Administrator -p couchbase --threads 4     

  Check Backup

/opt/couchbase/bin/cbbackupmgr info --archive /backup --repo repo1

/opt/couchbase/bin/cbbackupmgr list --archive /backup --repo repo1 

  Copy Files Between GCP Nodes:  

Copy from source cluster to bucket:

gsutil cp backup.tar gs://couchbase-bucket/

Copy from bucket to Target cluster:

gsutil cp gs://couchbase-bucket/backup.tar /tmp

  Restore:  

All buckets:

/opt/couchbase/bin/cbbackupmgr config --archive /restore --repo repo2 
/opt/couchbase/bin/cbbackupmgr restore --archive /restore --repo repo2 --cluster couchbase://10.128.0.4 -u Administrator -p couchbase --threads 4
   
    
Exclude One Bucket:

/opt/couchbase/bin/cbbackupmgr restore --archive /restore --repo repo2 --cluster couchbase://10.128.0.4 -u Administrator -p couchbase --threads 4 --exclude-buckets 'travel-sample'
    
    Exclude Two Buckets:
/opt/couchbase/bin/cbbackupmgr restore --archive /restore --repo repo2 --cluster couchbase://10.128.0.4 -u Administrator -p couchbase --threads 4 --exclude-buckets 'travel-sample,REST-TMP'

Note: Above are the commands used/mentioned in Module 6 of the Couchbase Database Administration Course. 

 

DISCLAIMER

The purpose of sharing the content on this website is to Educate. The author/owner of the content do not warrant that the information provided on this website is fully complete and shall not be responsible for any errors or omissions.The author/owner shall have neither liability nor responsibility to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the contents of this website. So, use the content of this website at your own risk.

This content has been shared under Educational And Non-Profit Purposes Only. No Copyright Infringement Intended, All Rights Reserved to the Actual Owner.

For Copyright Content Removal Please Contact us by Email at besttechreads[at]gmail.com

Post a Comment

Previous Post Next Post