Running MySQLdump for XAMPP in CentOS

醉酒当歌 提交于 2020-01-07 02:16:33

问题


Hopefully I am posting it in the right forums..

Basically, I am trying to run a script that will do a MySQL database dump which works when I run it manually, but crontab doesn't seem to run that particular script for some reason.

My crontab is setup as such (for testing purposes, running every minute):

* * * * * /opt/lampp/htdocs/xyz/backup/backup.sh

The script is setup as such:

#!/bin/bash
# Script to backup the database
/opt/lampp/bin/mysqldump -u root xyz > backup_$(date +%Y%m%d).sql
echo " backup_$(date +%Y%m%d)" > /opt/lampp/htdocs/xyz/backup/log.txt

I know the script runs, because the log.txt is created. But for some reason, no SQL file is generated. I also know that the line

/opt/lampp/bin/mysqldump -u root xyz > backup_$(date +%Y%m%d).sql

works because it generates the file if I run it at the command line.

Any help greatly appreciated!


回答1:


Try this:

/opt/lampp/bin/mysqldump -u root xyz > backup_$(date +%Y%m%d).sql

Put password of that root user -p(password) without space and it should work.




回答2:


What user ID is this script running under? It'll be trying to write your backup file into the homedir of that particular account. Make sure that this account has write privs for that dir, and can access all the parent dirs leading up to that spot.

Beyond that, note that your script is somewhat racey. Consider than you (maybe) will set the script to run at 11pm every day. If the dump takes more than 1 hour, you'll be dumping a DIFFERENT date into the log file (which you'll be overwriting, not appending, by the way, since you'r eusing >, not >>). To work around this, you'd want to generate/assign the date to a variable at the start of your script, then use that variable instead of more date calls down the road.




回答3:


So when crontab runs the shell script, the backup_(date).sql file is actually saved under the /root folder.

Running the shell script manually places the SQL file where the shell script is.



来源:https://stackoverflow.com/questions/13465357/running-mysqldump-for-xampp-in-centos

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!