0

We run daily backups of our MySQL server. Using the following script:

  [ ! -d "${DEST}" ] && mkdir -p "${DEST}"

FILE=${DEST}/mysql-live.${NOW}-$(date +"%T").tar.gz.bz2
# get around error
mysqldump --single-transaction -u $MUSER -h $MHOST -p$MPASS DB | bzip2 -k -v > $FILE

Now, when I try to extract with tar xvjf I get an error. It will unarchive with bunzip2 to a tar.gz file, but when I try to extract using tar xvf, xzvf, gunzip, it shows not a gzip archive. However, if I try to rename it to just a tar, it will show not a tar archive.

I'm slightly confused here as I'm running out of options, if anyone has any ideas. That would rock. It's on CentOS.

Hennes
  • 4,842
  • 1
  • 19
  • 29
Joseph
  • 293
  • 2
  • 7
  • 14
  • 1
    What error does tar throw, it may be important. – user9517 Jun 01 '14 at 21:59
  • Anything from not a tar archive, to not a gzip archive. I think I figured it out though. It looks like I just needed to rename the extracted file to a *.mysql file. – Joseph Jun 01 '14 at 22:05
  • You really should spend some time reading the relevant documentation and speak to your senior/manager about getting some education.# – user9517 Jun 01 '14 at 22:31

1 Answers1

3

Your command

mysqldump --single-transaction -u $MUSER -h $MHOST -p$MPASS DB | bzip2 -k -v > $FILE

says dump a database and pipe the output to bzip2 which should write it's stdout to $FILE.

The contents of stdin will be compressed and written to for example a.tar.gz.bz2. This doesn't create either a tar archive or a gzip compressed tar archive (.tar.gz), is simply creates a .bz2 compressed archive with a confusing name.

When you try to extract the contents of the archive (for reasons unknown) you attempt to use the tar utility and to you, unexpectedly get an error message, probably something like

tar -xvjf a.tar.gz.bz2
tar: This does not look like a tar archive
tar: Skipping to next header
tar: Exiting with failure status due to previous errors

Which is correct because the file is not a bzip compressed gzip compressed tar archive. You probably need something like

bunzip a.tar.gz.bz2

As you are not generating either a tar archive or a gzip compressed archive you should probably not make .tar.gz part of the filename as, as you have found it just creates confusion.

user9517
  • 115,471
  • 20
  • 215
  • 297
  • I noticed that and got it working. I realized it just compresses the mysql file, but renames it to avoid errors. Thanks! I got it working and made a note on the server :-) – Joseph Jun 01 '14 at 22:36