0

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.

4 Answers 4

1

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
4
  • 1
    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, 2013 at 23:19
  • That's a good point. Jun 5, 2013 at 18:23
  • could you please edit it?
    – Hengjie
    Jun 7, 2013 at 1:35
  • Done............................. Jun 7, 2013 at 13:40
1

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

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.

1
  • 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. Oct 11, 2010 at 18:01
1

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
1
  • the pwd for personal cron jobs (crontab -e) is your $HOME directory
    – chicks
    Nov 14, 2015 at 15:13

You must log in to answer this question.

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