Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

This is a very basic mysqldump script that will do a dump and store it locally.

Running mysqldump by itself works fine as does gzip (i.e. they are where they need to be in my path)

/usr/bin/mysqldump --database $DBNAME --opt --single-transaction -u $USER -p $PASS

But when I try to pipe the output to gzip and then write that to a file I run into an error:

/var/www/vhosts/meh/mysqlbackup/mysqlbackup.sh: line 18: /var/www/vhosts/meh/mysqlbackup/mehbackup.sql.gz: No such file or directory
mysqldump: Got errno 32 on write

Here is the line 18 referenced in the error:

/usr/bin/mysqldump --database $DBNAME --opt --single-transaction -u$USER -p$PASS | /usr/bin/gzip -9 > $OUTDIR$OUTFILE

That error number 32 seems to be a broken pipe error so... I'm assuming that , since mysqldump can run fine, I am having an issue writing the results? A permissions issue maybe?

The permissions on the dir I am writing to are 766 (rwxrw-rw-)

I am running this under super user permissions (su)

I want to set this up to run via cron but until I figure out why this is failing... no love.

share|improve this question

3 Answers 3

up vote 1 down vote accepted

See if you can do this:

$ echo "woo" | gzip > asdf.gz
$ gunzip asdf.gz
cat asdf

That should tell you that your gzip stuff is working fine. If you're not doing your gzip stuff the way I just did it, maybe try it the way I just did it.

In other words, try this:

/usr/bin/mysqldump --database $DBNAME --opt --single-transaction -u $USER -p $PASS | gzip > /var/www/vhosts/meh/mysqlbackup/dump.gz
share|improve this answer
What I find missing is that you don't have a > in the mysqldump command where as you did in your example regarding woo. Therefore, this command worked for me: /usr/bin/mysqldump --database $DBNAME --opt --single-transaction -u $USER -p $PASS | gzip > /var/www/vhosts/meh/mysqlbackup/dump.gz NOTE: the > after gzip –  Hengjie Jun 4 '13 at 23:19
That's a good point. –  Jason Swett Jun 5 '13 at 18:23
could you please edit it? –  Hengjie Jun 7 '13 at 1:35
Done............................. –  Jason Swett Jun 7 '13 at 13:40

Check path:

file /var/www/vhosts/meh/mysqlbackup/
ls -ald /var/www/vhosts/meh/mysqlbackup/

and create dir:

mkdir -p /var/www/vhosts/meh/mysqlbackup/
share|improve this answer

Another distinct possibility: you have "/var/www/vhosts/meh/mysqlbackup" in one instance and "/var/www/vhosts/meh/mysqlbackups" in another instance. Maybe that's it.

share|improve this answer
Ugh, sorry. That was a typo on my part while putting this in. It is correct in the actual script. Good point though, as such things can so easily be the problem. –  Lothar_Grimpsenbacher Oct 11 '10 at 18:01

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.