Created
April 29, 2021 14:57
-
-
Save Lotti/8cee1768d6f6d2adb2823e3c846bb773 to your computer and use it in GitHub Desktop.
Downloads documents from couchdb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
OUTPUT_COUCHDB_URL=xxxx | |
OUTPUT_COUCHDB_DBNAME=xxxx | |
OUTPUT_COUCHDB_USERNAME=xxxx | |
OUTPUT_COUCHDB_PASSWORD=xxxx | |
TMP_FILE=tmp-output.json | |
FOLDER=docs | |
LIMIT=1000 | |
SKIP=0 | |
rm -Rf "./${FOLDER}" | |
write_file() { | |
#NAME=$(echo "${1}" | jq --raw-output '._id') | |
echo "${1}" > "${2}${3}.json" | |
#echo "${1}" | jq '. | del(._id, ._rev)' > "${2}${NAME}.json" | |
} | |
while true; do | |
curl -X GET "${OUTPUT_COUCHDB_URL}/${OUTPUT_COUCHDB_DBNAME}/_all_docs?include_docs=true&limit=${LIMIT}&skip=${SKIP}" --user "${OUTPUT_COUCHDB_USERNAME}:${OUTPUT_COUCHDB_PASSWORD}" | jq '.rows[].doc' --compact-output --raw-output > "./${TMP_FILE}" | |
ROWS=$(jq --slurp 'length' "./${TMP_FILE}") | |
if [[ "${ROWS}" -eq "0" ]]; then | |
echo "EXIT" | |
break | |
fi | |
mkdir -p "./${FOLDER}/${SKIP}" | |
COUNT=$((0 + ${SKIP})) | |
while IFS= read -r LINE | |
do | |
COUNT=$((${COUNT} + 1)) | |
PATH_NAME="./${FOLDER}/${SKIP}/" | |
write_file "${LINE}" "${PATH_NAME}" "${COUNT}" | |
done < "./${TMP_FILE}" | |
SKIP=$((${LIMIT} + ${SKIP})) | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment