数据导出
cbexport
https://docs.couchbase.com/server/6.0/tools/cbexport-json.html
速度快,不支持n1ql.
例子
/opt/couchbase/bin/cbexport json -c couchbase://192.168.40.56 -u admin -p admin123 -b selling-products -o ./selling-products.json -f lines
0 0 * * * /{path}/cbexport json -c couchbase://{host} -u {username} -p {password} -b selling-products -o /{mount path}/selling-products.json -f lines -t {Number of threads}
n1ql2csv
https://github.com/couchbaselabs/n1ql2csv
导出数据过多不行,因为先通过rest api获取后面转csv处理。
n1ql rest api
https://docs.couchbase.com/server/6.5/n1ql/n1ql-rest-api/index.html
支持条件导出,速度快。
curl -v http://{username}:{password}@{host}:8093/query/service \
-d 'statement=SELECT * FROM `complete-product` where locale =“{locale}"' -o {locale}.json
一个参考脚本
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
##### configure start #####
couchbase_host=""
couchbase_user="admin"
couchbase_pwd="admin"
bucket_name_prefix="product_"
couchbase_bin_dir="/opt/couchbase/bin"
export_dir=$(pwd)
##### configure end #####
begin_time=`date +%s`
quantity=$1
if [ "$quantity" = "" ]; then
quantity=3
fi
if [ "$2" != "" ]; then
export_dir=$2
fi
locales=("de_de" "fr_fr" "nl_nl" "it_it" "en_gb" "sv_se" "au_au" "us_us" "de_at" "nl_be" "fr_be" "pl_pl" "es_es" "fr_ch" "de_ch" "pt_pt" "el_gr" "da_dk" "en_ie" "fi_fi" "hu_hu" "nb_no" "cs_cz" "ro_ro" "bg_bg" "sk_sk" "hr_hr" "sl_si" "lt_lt" "et_ee" "lv_lv")
i=1
while :
do
chunk_locales=${locales[@]:$((($i - 1) * $quantity)):$quantity}
if [[ "$chunk_locales" = "" ]]; then
break
fi
for locale in ${chunk_locales}; do
{
bucket_name="${bucket_name_prefix}${locale}"
echo "Export bucket:" $bucket_name
${couchbase_bin_dir}/cbexport json -c couchbase://${couchbase_host} -u ${couchbase_user} -p ${couchbase_pwd} -b "${bucket_name}" -o "${export_dir}/${bucket_name}.json" -f lines
}&
done
sleep 2
wait
let i++
done
wait
end_time=`date +%s`
echo "Total time:" $((($end_time-$begin_time)/60)) "m" $((($end_time-$begin_time)%60)) "s"
echo "done!"
cli 也可以使用n1ql: https://docs.couchbase.com/server/6.5/cli/cbq-tool.html
./cbq -e couchbase://192.168.40.104 -u admin -p admin123 -s "select * from \`catalog\` limit 1" -o /tmp/222selling-products.json -pretty=false
示例
1 0 * * * /{couchbase path}/bin/cbq -e couchbase://{host} -u {username} -p {password} -s "select * from \`catalog\` where \`table_type\`='category' " -o /{mount path}/category.json -pretty=false
2 0 * * * /{couchbase path}/bin/cbq -e couchbase://{host} -u {username} -p {password} -s "select * from \`catalog\` where \`table_type\`='attribute' and \`applicable_channel\`='1'" -o /{mount path}/attribute.json -pretty=false
3 0 * * * /{couchbase path}/bin/cbq -e couchbase://{host} -u {username} -p {password} -s "select * from \`catalog\` where \`table_type\`='category_attribute_relation' " -o /{mount path}/category_attribute_relation.json -pretty=false
Last updated
Was this helpful?