[Couchbase Server 4.5 DP] backup restore don't match numbers of backup doc

I has a Couchbase Server 4.5 DP on Ubuntu 12.04.5 LTS 64bit with 6055 docs (some docs has some attachments)
and I using the following command to backup the bucket:

/opt/couchbase/bin/backup create --name mydb --include-buckets mydb --dir /data/couchabse/backups

/opt/couchbase/bin/backup cluster --dir /data/couchabse/backups --host couchbase://localhost \
--username Admin --password password --name mydb

the logs shows as follow:

Backing up to 2016-03-10T15:51:11.895398384+08:00
Copied all data in 7s (Avg. 7.47MB/Sec)                                                                                                                                                  8365 items / 52.26MB
mydb                [===========================================================================================================================================================================] 100.00%

Backup successfully completed

Note: From Couchbase Console, mydb has 6055 docs, not 8365 docs. I guess 8365 items included attachments,Right?

Then, On my MAC I have installed a Couchbase Server 4.5 DP with a empty bucket mydb. I am using the follow command to prepare the restore:

backup create --name mydb --include-buckets mydb --dir /tmp/backups

then I copy mydb directory from Ubuntu to my MAC and replace the /tmp/backups/mydb, and restore the backup with:

backup restore --dir /tmp/backups --name mydb --host couchbase://localhost \
--username Admin --password password

The logs shows:

(1/1) Restoring backup 2016-03-10T15:51:11.895398384+08:00
Copied all data in 2s (Avg. 26.11MB/Sec)                                                                                                                                                 8365 items / 52.23MB
mydb                [===========================================================================================================================================================================] 100.00%

Restore completed successfully

But in Couchbase Console,I found mydb bucket has 8364 docs, Not 8365, Not 6055.

Sorry for the delay in getting this answered. I have been on vacation the past few days. First off, can you tell me what you mean by attachments? Also I’m assuming the Couchbase Console your referring to is the one accessed at localhost:8091?

One thing I also want to note is that Couchbase persists deletes and we back these up. If you have created or deleted any keys then this may account for the difference in documents backed up (6055 vs. 8365). I’m not sure this explains what you’re seeing though since when you restore everything you can see 8365 of the documents in your bucket when you restore the data.

I’ll also look into the off by one issue on the restore and get a test case for this to make sure we don’t have any issues in the future.

Thanks for reply.
I am using Couchbase Mobile(Sync Gateway 1.2.0) with Couchabse Server 3.1.0. and I restore the docs to Couchbase Server 4.5.0 DP.
the attachments mean I add some attachments to docs by Sync Gateway REST API.
So I guess 8365 items may be inclued the attachments?( one attachment = one item ?)
As you mentioned, do you means that 8365 docs included the normal docs,the attachments and the deleted docs? if the deleted docs will be restore, why Couchbase Console shows the bucket has 8365 items, not 6055 items?

I’m not as familiar with Couchbase Mobile as I am with Couchbase Server, but your explanation of what attachments are makes sense. It is likely that Couchbase Mobile stores a separate document in Couchbase Server and that is why you are seeing 8365 documents.

To answer your questions, I think one attachment is equal to one document. The 8365 documents includes the normal documents, attachments, and deleted documents. I’ll try to reproduce this issue later this week so I can get a better understanding of whether or not their are any issues.

It is correct that attachments are stored in separate items.

why from source couchbase console, the bucket shows 6055 docs(with attachments), and the target couchbase console shows 8365 docs(with attachments)?

I don’t know to be honest. One small possibility is that Sync Gateway cleaned up (compacted) away some old versions after the backup was made. The best way to get to the bottom of it is probably to write a small program to get all of the keys from one cluster and check them all on the other cluster. @mikew may have some other verification ideas.