0

I'm trying to do a diff on MySQL dumps (created with mysqldump and piped to bzip2), to see if there are changes between consecutive dumps. The followings are the tails of 2 dumps:

tmp1:

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2011-03-11  1:06:50

tmp2:

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2011-03-11  0:40:11

When I bzdiff their bzipped version:

$ bzdiff tmp?.bz2 
10c10
< -- Dump completed on 2011-03-11  1:06:50
---
> -- Dump completed on 2011-03-11  0:40:11

According to the manual of bzdiff, any option passed on to bzdiff is passed on to diff. I therefore looked at the -I option that allows to define a regexp; lines matching it are ignored in the diff. When I then try:

$ bzdiff -I'Dump' tmp1.bz2 tmp2.bz2

I get an empty diff. I would like to match as much as possible of the "Dump completed" line, though, but when I then try:

$ bzdiff -I'Dump completed' tmp1.bz2 tmp2.bz2
diff: extra operand `/tmp/bzdiff.miCJEvX9E8'
diff: Try `diff --help' for more information.

Same thing happens for some variations:

$ bzdiff '-IDump completed' tmp1.bz2 tmp2.bz2
$ bzdiff '-I"Dump completed"' tmp1.bz2 tmp2.bz2
$ bzdiff -'"IDump completed"' tmp1.bz2 tmp2.bz2

If I diff the un-bzipped files there is no problem:

$diff -I'^[-][-] Dump completed on' tmp1 tmp2

gives also an empty diff.

bzdiff is a shell script usually placed in /bin/bzdiff. Essentially, it parses the command options and passes them on to diff as follows:

OPTIONS=
FILES=
for ARG
do
    case "$ARG" in
    -*) OPTIONS="$OPTIONS $ARG";;
     *) if test -f "$ARG"; then
            FILES="$FILES $ARG"
        else
            echo "${prog}: $ARG not found or not a regular file"
            exit 1
        fi ;;
    esac
done
[...]
bzip2 -cdfq "$1" | $comp $OPTIONS - "$tmp"

I think the problem stems from escaping the spaces in the passing of $OPTIONS to diff, but I couldn't figure out how to get it interpreted correctly.

Any ideas?

EDIT @DerfK: Good point with the ., I had forgotten about them... I tried the suggestion with the multiple level of quotes, but that is still not recognized:

$ bzdiff "-I'\"Dump.completed.on\"'" tmp1.bz2 tmp2.bz2
diff: extra operand `/tmp/bzdiff.Di7RtihGGL'

3 Answers 3

0

At this point I would have given up on spaces and used Dump.completed so that the . matches the space (since this is a regex).

Bash strips a layer of quotes every time it evaluates the argument, as well as stripping a layer of quotes from what you typed when you hit return. Since that case statement insists that the option start with -, you'll need to try something like "-'\"IDump completed\"'" so that the bzdiff is executed with the argument -'"IDump completed"' which should be inserted in the $OPTIONS line as -"IDump completed" which should lead to diff being executed with -IDump completed as a single argument instead of two words.

0
0

No amount of quoting will help with this; quoting happens at the wrong level. bzgrep -e -I'Dump completed' or bzgrep -- -I'Dump completed' should work.

1
  • The question was about bzdiff, not bzgrep. I tried it, but it still doesn't work, yielding the same result as the quoting.
    – englebip
    Mar 15, 2011 at 15:38
0

I found a solution to this issue. The parsing of the options and the submission to diff was done incorrectly by bzdiff; a space was added before the first option that seems to throw things up in the air...

I did the following modifications to bzdiff:

$ diff bzdiff_orig /bin/bzdiff 
27c27,31
<     -*)   OPTIONS="$OPTIONS $ARG";;
---
>     -*)   if test -z "$OPTIONS"; then
>       OPTIONS="$ARG"
>         else
>             OPTIONS="$OPTIONS $ARG"
>         fi ;;
57c61
<                         bzip2 -cdfq "$1" | $comp $OPTIONS - "$tmp"
---
>                         bzip2 -cdfq "$1" | $comp "$OPTIONS" - "$tmp"

With the modified code the diff proceeds as expected:

$ bzdiff -I"Dump completed" tmp?.bz2
$ bzdiff -I"This should not match" tmp?.bz2
9c9
< -- Dump completed on 2011-03-11  1:06:50
---
> -- Dump completed on 2011-03-11  0:40:11

I will e-mail the bzip developer to file a bug report.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .