Backup MySQL with Innobackup combined with scheduled tasks

Source: Internet
Author: User
Tags chmod

Write a script to automate full and incremental backups
Full backup

vim /root/allbak.sh#!/bin/bash[ ! -e /backup ]&& mkdir /backup   //新建个文件夹专门放备份文件的day=`date +%F`                     //定义日期是时间user=rootpass=123456innobackupex --user $user --password $pass /backup/allbak${day} --no-timestamp   //用innobackupex做完全备份mysql -u$user -p$pass -e "flush logs" ```   //启用binlog日志,每次完全备份之后,刷新一遍binlog日志

vim/root/newbak.sh
#!/bin/bash
d1= date +%f //define time, use date to differentiate
d2= date +%f-d "-1 days" //Find yesterday's date to indicate the last backup file
Dir1=/backup/allbak${d2}//Full backup file made yesterday
Dir2=/backup/newbak${d2}//Incremental backup file made yesterday
User=root
pass=123456
[!-e/backup]&& Mkdir/backup//If the file does not exist, create a folder
If [-e ${dir1}];then//Judging yesterday Do is full backup
Innobackupex--user $user--password $pass--incremental/backup/newbak${d1}--incremental-basedir=${dir1} --no-timestamp//Specify the full backup file that was backed up yesterday
Elif [-e ${dir2}];then//To determine that the incremental backup was done yesterday
Innobackupex--user $user--password $pass-- INCREMENTAL/BACKUP/NEWBAK${D1}--incremental-basedir=${dir2}--no-timestamp//Specify the incremental backup file that was backed up yesterday
else
Innobackupex--user $user--password $pass/backup/allbak${d1}--no-timestamp
//yesterday did not make an incremental backup, and did not do a full backup, then do a full backup.
Fi

加权限:chmod +x /root/allbak.sh chmod +x /root/newbak.sh写计划任务:crontab -e 00  03 * * 1 /root/allbak.sh  &>/dev/null      //每周一的凌晨3点执行完全备份00   04  * * 2-7 /root/newbak.sh    & >/dev/null  //每周二到周7的凌晨4点执行增量备份重启crond服务systemctl restart crond systemctl enable crond

Backup MySQL with Innobackup combined with scheduled tasks

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.