Home >Backend Development >PHP Tutorial >Linux automatic database backup fails

Linux automatic database backup fails

WBOY
WBOYOriginal
2016-08-29 08:50:48924browse

shell
dbbackup.sh:

<code>mysqldump -uname -ppassword dbname | gzip > /www/web/mysqlbackup/xiangyanghua`date +%Y-%m-%d_%H%M%S`.sql.gz
</code>

crontab

<code>37 22 * * * root /www/web/mysqlbackup/dbbackup.sh</code>

Please tell me what’s wrong.

Reply content:

shell
dbbackup.sh:

<code>mysqldump -uname -ppassword dbname | gzip > /www/web/mysqlbackup/xiangyanghua`date +%Y-%m-%d_%H%M%S`.sql.gz
</code>

crontab

<code>37 22 * * * root /www/web/mysqlbackup/dbbackup.sh</code>

Please tell me what’s wrong.

1. Run the command directly, you can do it without
2. Is the crontab service turned on?

1 The crontab task will be executed using the current user identity, adding root is useless;
2 Execute the command manually to see if it succeeds or if there are any other errors;
3 Add it to your dbbackup.sh script Output the log content to a file, such as adding

to the start line and end line
<code>echo $(date)--start >> /tmp/xxx.log
</code>

This method is used to determine whether the script has been executed and at which step the error occurred;
4 The standard output and error output of the execution are added to the crontab task

<code>37 22 * * * /www/web/mysqlbackup/dbbackup.sh > /tmp/dbback.log 2>&1
</code>

5 Executable permissions for scripts
6 If mysqldump is installed from source code, you need to pay attention to the path environment variable. Crontab may not be able to read the path, so mysqldump should write the absolute path in the script;

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn