Backup mysql through innobackup combined with scheduled tasks
The following mainly brings you backup mysql through innobackup combined with planned tasks. I hope these contents can bring you practical use, which is also the main purpose of my editor to achieve backup mysql through innobackup combined with scheduled tasks. All right, don't talk too much nonsense, let's just read the following.
Write a script to make automatic full and incremental backups
Full backup
Refresh the binlog log
Vim / root/newbak.sh
#! / bin/bash
D1=date +% F / / defines the time, distinguished by date
D2=date +% F-d "- 1 days" / / find yesterday's date to indicate the backup file from the last backup
Dir1=/backup/allbak$ {d2} / / full backup files made yesterday
Dir2=/backup/newbak$ {D2} / / incremental backup files made yesterday
User=root
Pass=123456
[!-e / backup] & & mkdir / backup / / create a folder if the file does not exist
If [- e ${dir1}]; then / / judged that what was done yesterday was a full backup
Innobackupex-- user $user-- password $pass-- incremental / backup/newbak$ {D1}-- incremental-basedir=$ {dir1}-- no-timestamp / / specifies the full backup file that was backed up yesterday
Elif [- e ${dir2}]; then / / judged that what was done yesterday was an incremental backup
Innobackupex-- user $user-- password $pass-- incremental / backup/newbak$ {D1}-- incremental-basedir=$ {dir2}-- no-timestamp / / specify the incremental backup files backed up yesterday
Else
Innobackupex-user $user-password $pass / backup/allbak$ {D1}-no-timestamp
/ / if there was neither incremental backup nor full backup yesterday, do a full backup.
Fi
Add permission: chmod + x / root/allbak.sh chmod + x / root/newbak.sh write schedule task: crontab-e 00 03 * * 1 / root/allbak.sh & > / dev/null / / perform a full backup 00 04 * * 2-7 / root/newbak.sh & > / dev/null / / perform an incremental backup to restart the crond service systemctl restart crond at 4: 00 a.m. from Tuesday to Sunday
Systemctl enable crond
For the above about the combination of innobackup with scheduled tasks to achieve backup mysql, we do not think it is very helpful. If you need to know more, please continue to follow our industry information. I'm sure you'll like it.