An error occurred while backing up the database automatically in Linux.

Source: Internet
Author: User
Shelldbbackup. sh: {code...} crontab {code. Shell
Dbbackup. sh:

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

Crontab

37 22 * * * root /www/web/mysqlbackup/dbbackup.sh

Where is the problem.

Reply content:

Shell
Dbbackup. sh:

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

Crontab

37 22 * * * root /www/web/mysqlbackup/dbbackup.sh

Where is the problem.

1. run the command directly.
2. is the crontab service enabled?

1 The crontab task will be executed as the current user. it is useless to add the root user;
2. run the command manually to check whether the command is successful or whether there are other errors;
3. add the log content to the file in your dbbackup. sh script, for example, add the log content to the start line and end line.

echo $(date)--start >> /tmp/xxx.log

This method is used to determine whether the script is executed and where an error occurs;
4. add standard output and error output to the crontab task.

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

5. executable permissions of the script
6. if mysqldump is installed in source code, you need to pay attention to the path environment variable problem. crontab may not be able to read the path, so in the script, mysqldump should write the absolute path;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.