MySQL scheduled backup

Source: Internet
Author: User

Backup process
    • Create a backup directory

      $ cd ~$ mkdir backup$ cd backup
    • To create a backup Shell script:
      Vim databasenamebackup.sh

      #!/bin/bash
      Mysqldump-uusername-ppassword DBName | Gzip > ~/dbname$ (date +%y%m%d%h%m%s). sql.gz
      Attention:
      Replace the username with the actual user name;
      Replace the password with the actual password;
      Replace the DBName with the actual database name;

    • Add executable permissions
      chmod u+x databasenamebackup.sh

    • Edit the/etc/crontab file directly, that is, Vi/etc/crontab, and add the appropriate tasks.
Crond

is the command that Linux uses to execute programs on a regular basis. This task dispatch command is started by default when the operating system is installed. The Crond command periodically checks to see if there is any work to be done and the work will be performed automatically if there is work to be done. You can start and close this service in the following ways:
/sbin/service Crond Start//Startup service
/sbin/service Crond stop//Shut down service
/sbin/service crond Restart//Restart service
/sbin/service Crond Reload//Reload Configuration

crontab command Options

The Cron service provides the crontab command to set the Cron service, and here are some of the parameters and instructions for this command:
Crontab-u//Set a user's Cron service, which is usually required by the root user when executing this command
CRONTAB-L//list details of a user cron service
Crontab-r//Delete a cron service with no users
CRONTAB-E//Edit a user's cron service

For example, root to view your cron settings: Crontab-u root-l
Again, for example, Root wants to delete Fred's cron settings: Crontab-u fred-r
When editing the Cron service, the edited content has some formatting and conventions, input: Crontab-u root-e

Example of a timed task

Crontab format: Time-sharing weekly command to run

    第 1 列分钟 1~59    第 2 列小时 1~23(0 表示子夜)    第 3 列日 1~31    第 4 列月 1~12    第 5 列星期 0~6(0 表示星期天)    第 6 列要运行的命令

crontab Example

 5 * * * * ls//Specify 5 minutes per hour to execute the LS command 30 5 * * LS//Specify 5:30 per day to execute the LS command 7 8 * * ls//Specify 7:30 of the monthly 8th to execute the LS command 30 5 8 6 * ls//Specify June 8 5:30 of each year to execute the LS command 6 * * 0 ls Specify 6:30 per Sunday to execute the LS command [note: 0 for Sunday, 1 for Week 1, and so on, can also be expressed in English, Sun said Sunday, Mon for Monday, etc. ] 3 10,20 * * ls//monthly 10th and 20th 3:30 Execute ls command [note: "," used to connect multiple discontinuous periods] 25 8-11 * * ls//8-11 points per day for the 25 minute execution of the LS command [note: "-" to connect a continuous period of time] */15 * * * * ls//per 15-minute execution of the LS command [i.e. No. 0 15 30 45 60 minute execution of the LS command per hour] 6 */10 * ls//Every month, the LS command is executed every 10 days 6:30 [ That is, the monthly 1, 11, 21, 31st is 6:30 to execute the LS command. ] 7 * * * Root run-parts/etc/cron.daily//daily 7:50 execute all executable files in the/etc/cron.daily directory as root [note: The Run-parts parameter indicates that all executables in the following directory are executed. ]

Add a Scheduled task

crontab -e01   3 * * * root/home/backup/DatabaseName.sh 表示每天 3 点钟执行备份

MySQL scheduled backup

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.