Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

couchdb-dump doesn't work with busybox's grep anymore #84

Open
fungiboletus opened this issue Mar 3, 2020 · 1 comment
Open

couchdb-dump doesn't work with busybox's grep anymore #84

fungiboletus opened this issue Mar 3, 2020 · 1 comment

Comments

@fungiboletus
Copy link
Contributor

Since 2640981, the script fails silently when busybox's grep is used to do the backup. The U option is not recognized and it produces the following error :

grep: unrecognized option: U

However, it doesn't stop the script and produces a file. It's when you try to restore it that couchdb complains with the following error :

... ERROR: CouchDB Reported: {"error":"bad_request","reason":"invalid UTF-8 JSON"}

In my case, I used alpine linux to do the backups and it's busybox's grep by default but I was able to fix the issue by installing Gnu grup with the command apk add grep. However I have two weeks of backups that are not valid, as I didn't detect the issue because the script doesn't fail and I don't test restores frequently enough (my bad). Do you think it could be possible to fix the existing files so I can restore them ?

The line in question:

if grep -qU $'\x0d' $file_name; then

@camo-f
Copy link

camo-f commented Mar 17, 2021

Hi @fungiboletus, I ran into the same issue.
I found out that you can just install grep to override busybox's grep :

/ # grep --help
BusyBox v1.31.1 () multi-call binary.
/ # apk add --no-cache grep
/ # grep --version
grep (GNU grep) 3.4
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

This version includes the missing -U option (grep --help output) :

  -U, --binary              do not strip CR characters at EOL (MSDOS/Windows)

Same thing for du -P : busybox's du does not have -P option.

apk add --no-cache coreutils

On a side note, maybe this option could be removed, as it is the default behavior on "default" du :

  -P, --no-dereference  don't follow any symbolic links (this is the default)

Tested in Alpine Linux 3.12 Docker image. The downside is it requires more packages so the Docker image is weighed down by ~2MB (assuming you're running the script in a container).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants