danielebailo/couchdb-dump

Getting error - sed: 1: "test.json": undefined label 'est.json' (Mac OS X 10.10.4)

Closed this issue · 4 comments

Im getting an error I don't understand (Mac OS X 10.10.4)

This is the command...
bash couchdb-backup.sh -b -H 127.0.0.1 -d test -f test.json

This is the output
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 961k 0 961k 0 0 6875k 0 --:--:-- --:--:-- --:--:-- 6916k
... INFO: File contains Windows carridge returns- converting...
... INFO: Completed successfully.
... INFO: Amending file to make it suitable for Import.
... INFO: Stage 1 - Document filtering
sed: 1: "test.json": undefined label 'est.json'
Stage failed.

Seems like its tripping over something there that I can't make out. Any suggestions appreciated.

Pretty odd; could you throw us the output from:

bash -x couchdb-backup.sh -b -H 127.0.0.1 -d test -f test.json

Be sure to strip out any sensitive information from the output- but that should make it nice and clear what's going wrong :)

Thanks for your reply. Here is the output ...

+ scriptversionnumber=1.1.1
+ '[' x-b = x ']'
+ username=
+ password=
+ backup=false
+ restore=false
+ port=5984
+ OPTIND=1
+ lines=5000
+ attempts=3
+ getopts ':h?H:d:f:u:p:P:l:t:a:V?b?B?r?R?' opt
+ case "$opt" in
+ backup=true
+ getopts ':h?H:d:f:u:p:P:l:t:a:V?b?B?r?R?' opt
+ case "$opt" in
+ url=127.0.0.1
+ getopts ':h?H:d:f:u:p:P:l:t:a:V?b?B?r?R?' opt
+ case "$opt" in
+ db_name=test
+ getopts ':h?H:d:f:u:p:P:l:t:a:V?b?B?r?R?' opt
+ case "$opt" in
+ file_name=test.json
+ getopts ':h?H:d:f:u:p:P:l:t:a:V?b?B?r?R?' opt
+ shift 7
+ '[' '' = -- ']'
+ '[' '!' x = x ']'
+ '[' true = true ']'
+ '[' false = true ']'
+ '[' true = false ']'
+ '[' x127.0.0.1 = x ']'
+ '[' xtest = x ']'
+ '[' xtest.json = x ']'
+ file_name_orig=test.json
++ uname -a
++ grep -ci darwin
+ '[' '!' 1 = 0 ']'
++ sysctl -n hw.ncpu
+ cores=8
+ '[' '!' x = x ']'
++ expr 8 - 1
+ threads=7
+ case $attempts in
+ true
++ echo 127.0.0.1
++ grep -c http
+ '[' '!' 0 = 1 ']'
+ url=http://127.0.0.1
++ echo http://127.0.0.1
++ egrep -c ':[0-9]*$'
+ '[' '!' 0 = 1 ']'
+ url=http://127.0.0.1:5984
+ '[' '!' x = x ']'
+ '[' '!' x = x ']'
+ '[' '!' x = x ']'
++ echo http://127.0.0.1:5984
++ grep -ic '^https://'
+ '[' 0 = 1 ']'
++ which curl
+ '[' x/usr/bin/curl = x ']'
+ '[' true = true ']'
+ '[' false = false ']'
+ '[' -f test.json ']'
+ curl -X GET 'http://127.0.0.1:5984/test/_all_docs?include_docs=true&attachments=true' -o test.json
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  5363    0  5363    0     0  2647k      0 --:--:-- --:--:-- --:--:-- 5237k
+ '[' '!' 0 = 0 ']'
++ head -n 1 test.json
++ grep '^{"error'
+ ERR_CHECK=
+ '[' '!' x = x ']'
++ file test.json
++ grep -c CRLF
+ '[' 1 = 1 ']'
+ echo '... INFO: File contains Windows carridge returns- converting...'
... INFO: File contains Windows carridge returns- converting...
++ du -P -k test.json
++ awk '{print$1}'
+ filesize=8
+ checkdiskspace test.json 8
+ location=test.json
+ KBrequired=8
+ '[' xtest.json = x ']'
+ '[' x8 = x ']'
+ stripdir=test.json
++ df -P -k test.json
++ tail -n 1
++ awk '{print$4}'
++ sed -e 's/K$//'
+ KBavail=121838972
+ '[' 121838972 -ge 8 ']'
+ return 0
+ tr -d '\r'
+ '[' 0 = 0 ']'
+ mv test.json.tmp test.json
+ '[' 0 = 0 ']'
+ echo '... INFO: Completed successfully.'
... INFO: Completed successfully.
+ echo '... INFO: Amending file to make it suitable for Import.'
... INFO: Amending file to make it suitable for Import.
+ echo '... INFO: Stage 1 - Document filtering'
... INFO: Stage 1 - Document filtering
++ du -P -k test.json
++ awk '{print$1}'
+ '[' 8 -ge 256000 ']'
++ wc -l test.json
++ awk '{print$1}'
+ KBreduction=0
++ du -P -k test.json
++ awk '{print$1}'
+ filesize=8
++ expr 8 - 0
+ filesize=8
+ checkdiskspace test.json 8
+ location=test.json
+ KBrequired=8
+ '[' xtest.json = x ']'
+ '[' x8 = x ']'
+ stripdir=test.json
++ df -P -k test.json
++ tail -n 1
++ awk '{print$4}'
++ sed -e 's/K$//'
+ KBavail=121838972
+ '[' 121838972 -ge 8 ']'
+ return 0
+ sed -i 's/.*,"doc"://g' test.json
sed: 1: "test.json": undefined label 'est.json'
+ '[' '!' 1 = 0 ']'
+ echo 'Stage failed.'
Stage failed.
+ exit 1

I've run into this with sed. Apparently (and I think this was changed recently), sed requires a backup filename option to be specified - notice the empty parentheses. Example below of code that will throw error, and that which will solve it:

throws same error:
sed -i 's|_oldstring|new_string|' test.json

works on OSX 10.11:
sed -i '' 's|_oldstring|new_string|' test.json

Same as #36 - fix has been merged.