mysqldump: Got errno 32 on write

后端 未结 11 548
心在旅途
心在旅途 2021-01-01 09:03

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         


        
11条回答
  •  -上瘾入骨i
    2021-01-01 09:15

    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.

提交回复
热议问题