问题
I used this script for years on my VPS. And it's still working.
DBLIST=`mysql -uroot -pROOT_PASSWORD -ANe"SELECT GROUP_CONCAT(schema_name) FROM information_schema.schemata WHERE schema_name NOT IN ('information_schema','performance_schema')" | sed 's/,/ /g'`
MYSQLDUMP_OPTIONS="-uroot -pROOT_PASSWORD --single-transaction --routines --triggers"
BACKUP_DEST="/home/backup/db/"
for DB in `echo "${DBLIST}"`
do
mysqldump ${MYSQLDUMP_OPTIONS} ${DB} | gzip > ${BACKUP_DEST}/${DB}.sql.gz &
done
wait
tar -czvf /home/backup/db2/`date +\%G-\%m-\%d`_db.tar.gz ${BACKUP_DEST}
Now I'm moving to another hosting. I 'm trying to use the same script (of course I changed ROOT_PASSWORD with the new credentials) but I don't know why I get this:
mysqldump: Got errno 32 on write
mysqldump: Got errno 32 on write
mysqldump: Got errno 32 on write
mysqldump: Got errno 32 on write
mysqldump: Got errno 32 on write
mysqldump: Got errno 32 on write
mysqldump: Got errno 32 on write
mysqldump: Got errno 32 on write
mysqldump: Got errno 32 on write
mysqldump: Got errno 32 on write
mysqldump: Got errno 32 on write
mysqldump: Got errno 32 on write
mysqldump: Got errno 32 on write
回答1:
20:47:59 0 ~] $ perror 32
OS error code 32: Broken pipe
So errno 32 is "broken pipe". You're piping the mysqldump output to gzip
, so this means gzip terminated prior to mysqldump finished. Could e.g. be because your disk is full, or gzip surpassed any max CPU time/usage your host has in place.
回答2:
Make sure the folder /home/backup/db/ (which your are using to store the backup) has write access permission (to quick check: try using chmod -R 777 on that folder and run the script to make sure).
回答3:
I had the same problem due to a couple of typos.
I typed the name of the db user incorrectly. I had
"db_user_1"
when he was really"db_user1"
.After the pipe I forgot the
>
ingzip > myfile.tar.gz
.
But I recommend you upgrade to MySQL 5.6+ asap, so you can stop exposing database passwords other users.
Check out this answer on StackOverflow.
回答4:
Faced with the same problem. I do not know why exactly, but if you add the utility PV concluded that all works. Maybe it depends on your shell bash/sh.
sudo apt-get install pv
PipeViewer it a very usefull utility, it allows you to visualize processes of writing to disk, for example.
Script for example
mysqldump ${MYSQLDUMP_OPTIONS} ${DB} | gzip | pv > ${BACKUP_DEST}/${DB}.sql.gz
回答5:
I was using mysqldump
from the CLI and trying to pipe to gzip and/or a file and getting a "permission denied" error.
Even as sudo
, I was getting an error because although I was running mysqldump
as sudo
, the pipe was still trying to use the user account I was logged in to the shell as to write the output. In this case, my shell user account did not have permissions to write to the target directory.
To get around this, you can use the tee
command in conjunction with sudo
:
mysqldump --single-transaction --routines --events --triggers --add-drop-table --extended-insert -u backup -h 127.0.0.1 -p --all-databases | gzip -9 | sudo tee /var/backups/sql/all_$(date +"%Y_week_%U").sql.gz > /dev/null
The | sudo tee /var/backups/...
is what lets us pipe to a directory that is only writable by root
. The > /dev/null
suppresses tee
from dumping its output directly to the screen.
回答6:
Check if the folder exist in your location, /home/backup/db/
if no, create every subfolder.
Command: mkdir /home/backup/db/
then run your command again.
回答7:
I was surprised I couldn't do a dump of my DB, I was able to do it the day before. Now, I was getting this error.
As nos said, the error message means Broken pipe, which means the output cannot be written to disk. In my case, my SSH user had no permission to write in the folder I was targeting in my mysqldump instruction.
You can output your dump in your /home/your_user directory to see it you still get the same error. Doing so solved my problem.
回答8:
Errno 32 is "broken pipe" so any error that is happening with the pipe destination (in this case gzip) will cause errno 32. If the directory structure has changed and your ${BACKUP_DEST}
no longer refers to a directory that exists this problem would occur.
I would debug this by piping something else to your gzip command or creating an uncompressed backup not involving gzip.
回答9:
Its so old topic, but I'm facing that problem and find that:
My file name: db_26/03.tar.gz
its raising an error like above; but when I use: db.tar.gz
there is no error.
So you should check your file name
回答10:
I was seeing this error, when piping mysqldump output to s3cmd. It was caused by using the wrong version of s3cmd. On Ubuntu Trusty and Debian Wheezy the packaged version of s3cmd command doesn't support stdin (because they have version 1.1.0).
回答11:
What helped me with this problem is
export LANG=C
prior to running mysqldump per https://github.com/netz98/n98-magerun/issues/771
来源:https://stackoverflow.com/questions/22288271/mysqldump-got-errno-32-on-write