Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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/ 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
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

For me I wasn't executing the cron as root user, so I had to change folder owner and permission

chown user1 /home/user1/public_html/backups
chmod 755 /home/user1/public_html/backups

Then I was getting the same error: No such file or directory mysqldump: Got errno 32 on write

I add a dot before the public_html (the root folder for user1) and worked fine.

mysqldump -u user1_usr -h localhost -p'123123' db_db1 | gzip -f > ./public_html/backups/db-2015-11-14-0722.sql.gz
share|improve this answer
the pwd for personal cron jobs (crontab -e) is your $HOME directory – chicks Nov 14 '15 at 15:13

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.