Get the App
SLTechnology News&Howtos  ›  Database  › 

Backup mysql with innobackup combined with scheduled tasks

Shulou Source: shulou.com Published: 2022-06-01 09:00:19 10月21日 Update

Write a script to make automatic full and incremental backups

Full backup

Vim / rootspur allbak.shrootspur day= / backup/ / create a new folder dedicated to backup files day= `date +% F` / / the defined date is the time user=rootpass=123456innobackupex-- user $user-- password $date / backup/allbak$ {day}-no-timestamp / / make a full backup with innobackupex mysql-u$user-p$pass-e "flush logs" ``/ / enable binlog logs, after each 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 systemctl enable crond at 4: 00 a.m. from Tuesday to Sunday

Tags: Backup File Increment date folder Log time Task permission Monday Tuesday script previous Service Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Shulou Tech Info Apple Linux Shulou Technology