【问题标题】:CouchDB Replication verifyCouchDB 复制验证
【发布时间】:2015-09-22 12:31:58
【问题描述】:

我正在寻找一种简单的方法来验证复制的文档,它们都被转移了。 另外,当某些文档在复制过程中出现错误时,如何检查,是哪一个和/或为什么?

现在,我有一个想法,我可以检查源上的当前检查点序列。然后列出 source/_changes 中的所有 id,然后从目标数据库中 HEADing(或 GETing)文档并验证它们的存在(或值)。

【问题讨论】:

  • 您说的是Master-Slave 还是Master-Master 复制?要遵循的策略可能是:列出源中的所有 doc._rev,并将它们与目标 couchdb 进行比较。
  • 我说的是Master-Slave,但我不排除Master-Master。

标签: couchdb replication


【解决方案1】:

用于检查两个服务器 dbs 和 doc 计数匹配的简单 nagios 脚本 - 可以改进以检查每个 dbs 之间的 _rev 匹配。

    #!/usr/local/bin/bash
    # nagios check script to make sure 2 couch servers are the same
    #
    # ie: have same dbs
    #     have same number of documents in each db
    #
    # ./check_couch_dbs 192.168.1.2 192.168.1.3
    #
    # Needs fdescfs for bash redirects
    # 
    # Needs npm - as root: 'pkg install npm'
    # Needs json - as root: 'npm install -g json'
    # https://github.com/zpoley/json-command
    #
    #
    # check_couch_dbs command definition example
    #
    #    define command{
    #       command_name    check_couch_dbs
    #       command_line    $USER1$/check_couch_dbs $ARG1$ $ARG2$
    #       } 
    #

    host1=$1
    host2=$2

    difference_threashold=10

    dbs1=`curl -s http://$host1:5984/_all_dbs | json -ga  | grep -v -E '_replicator|_users' | sort`
    dbs2=`curl -s http://$host2:5984/_all_dbs | json -ga  | grep -v -E '_replicator|_users' | sort`

    dif=`diff -y --suppress-common-lines -b -s <(echo "$dbs1")  <(echo "$dbs2")`

    err=""
    msg=""
    exitcode=0
    if [[ "$dif" == *identical* ]]; then
            msg+="Couchdbs lists match"
    fi
    if [[ "$dif" == *\<* ]]; then
            err+="ERROR - db missing from $host2 \n"
            exitcode=2
    fi
    if [[ "$dif" == *\>* ]]; then
            err+="ERROR - db missing from $host1 \n"
            exitcode=2
    fi

    if [[ $exitcode -gt 0 ]]; then
            echo -e -n $err
            echo "$dif"
            err=""
    #       exit $exitcode
    fi

    dbs=`echo -e "$dbs1\n$dbs2" | sort | uniq`
    #echo "$dbs"

    for db in $dbs; do
            count1=`curl -s http://$host1:5984/$db | json doc_count`
            if [ -z "$count1" ]; then continue; fi  #no db
            count2=`curl -s http://$host2:5984/$db | json doc_count`
            if [ -z "$count2" ]; then continue; fi  #no db
            if [ "$count1" -ne "$count2" ]; then

                    if [ "$count1" -gt "$count2" ]; then
                            difference=$(($count1 - $count2))
                    else
                            difference=$(($count2 - $count1))
                    fi
                    if [[ $difference -gt $difference_threashold ]]; then
                    err+="ERROR - $db count difference $host1: $count1  != $host2: $count2 - difference: $difference\n"
                            exitcode=2
                    else
                            err+="WARNING - $db count difference $host1: $count1 != $host2: $count2 - difference: $difference\n"
                            if [[ $exitcode -lt 1 ]]; then
                                    exitcode=1
                            fi
                    fi
            fi
    done

    if [[ $exitcode -gt 0 ]]; then
            echo -e -n $err $msg
            exit $exitcode
    else
            echo -e "OK - $msg - doc_count match"
            exit $exitcode
    fi

【讨论】:

    【解决方案2】:

    睡过之后我认为下面将涵盖所有文档和_revs的比较

        #!/usr/local/bin/bash
    
        db1=`curl -s http://192.168.1.2:5984/mydb/_all_docs`
        db2=`curl -s http://192.168.1.3:5984/mydb/_all_docs`
    
        dif=`diff -y --suppress-common-lines -b -s <(echo "$db1")  <(echo "$db2")`
    
        echo $dif
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-06
      • 2019-07-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多