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

Linux automatic database backup fails

WBOY
Release: 2016-08-29 08:50:48
Original
939 people have browsed it

shell
dbbackup.sh:

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

crontab

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

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>
Copy after login
Copy after login

crontab

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

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>
Copy after login

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>
Copy after login

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;

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template