Linux mysql regular backup and compression, linuxmysql

Source: Internet
Author: User

Linux mysql regular backup and compression, linuxmysql

1. Check whether the mysql BACKUP command works.

Create a backup directory under the var directory and a mysql directory under the backup Directory to store mysql backup files

Cd to the/var/backup Directory

 mysqldump -uroot -pwh5268925 zhaochao > mysql/zhaochao.sql
If yes, zhaochao. SQL backup files will be available under/var/backup/mysql.



2. Create a backup script

Create a file msyql-backup.sh under/var/backup, the file content is as follows, save the file

JIRA_FILE_NAME=zhaochao-`date +%Y%m%d%H%M%S`;cd /var/backup/mysql/mysqldump -uroot -pwh5268925 zhaochao > ${JIRA_FILE_NAME}.sqltar -zcvf ${JIRA_FILE_NAME}.sql.tar.gz ${JIRA_FILE_NAME}.sqlrm -rf ${JIRA_FILE_NAME}.sql

3. Run the script to check whether the script can be correctly executed.

Cd to the/var/backup Directory to run the./mysql-backup.sh script, if correct, the/var/backup/mysql directory will generate a backup file named with time and compressed



4. Set the timer and regularly execute the mysql-backup.sh script

Create the crontest. cron file under/var/backup as follows:

15,30,45,59 * * * *  /var/backup/mysql-backup.sh

Execute the script every 15 minutes.


5. Add the timer file to the timer.

crontab crontest.cron
6. Check whether the scheduled task is added to crontab-l in the system.

[root@iZ23l2efmpqZ backup]# crontab -l15,30,45,59 * * * *  /var/backup/mysql-backup.sh

7. Cancel the scheduled task crontab-r

[root@iZ23l2efmpqZ backup]# crontab -l15,30,45,59 * * * *  /var/backup/mysql-backup.sh[root@iZ23l2efmpqZ backup]# crontab -r        [root@iZ23l2efmpqZ backup]# crontab -lno crontab for root




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.