#!/bin/bash# author: movekj# descript: backup mysql. full backup in sunday,incremental backup in other day. (for innodb store engine) # version: 0.0.1 ### define variablespath= "/ usr/java/latest/bin:/usr/lib64/qt-3.3/bin:/usr/java/latest/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/ Sbin:/usr/bin:/root/bin "backupuser=backuperbackuppassword= ... 1workpath=/home/backuplogpath=/home/backup/log/fullbackuppath=/home/backup/full/increbackuppath=/home/backup/ incre/dayofweek= ' date +%u ' weekofyear= ' date +%w ' date= ' date +%f ' ### define Functioncreatebackuppath () {if [ ! -d $1$2 ]thenmkdir -p $1$2 && echo -e "' Date ' \033[31m$1$2 is create successful!\033[0m" #> > $LogPath $weekofyear/backup_$date.log fi}deleteoldbackup () {backupnum= ' ls $1 | wc -L ' if [ $BackupNum -gt 3 ]thenoldbackupnum=$[$BackupNum -3]oldbackup= ' ls -t $1 | tail -$OldBackupNum ' ### find old backupfor i in $OldBackupdosudo rm -rf $1$I && echo "' Date ' $1$i is deleted! " >> ${logpath}backup_delete.logdonefi}delete () { DeleteOldBackup $FullBackupPath ### DELETE OLD full backup deleteoldbackup $IncreBackupPath ### DELETE OLD INCREMENTAL BACKUP #DeleteOldBackup $LogPath ### delete old log file }createbackuppath $LogPath $WeekOfYear ### create backup log pathcreatebackuppath $FullBackupPath $WeekOfYear ## CREATE FULL BACKUP PATHCreateBackupPath $IncreBackupPath $ weekofyear ### create incremental backup path### start progressif [ $DayOfWeek -eq 1 ]theninnobackupex --user= $BackupUser -- password= $BackupPassword $FullBackupPath $weekofyear 2>> $LogPath $weekofyear/full_backup_$ date.log >> $LogPath $weekofyear/full_backup_$date.logif [ $? -eq 0 ] thenDelete fielif [ $DayOfWeek -eq 2 ]thennewestfullbackup= ' ls -t $FullBackupPath $ Weekofyear | head -1 ' ### FIND NEWEST FULL backupinnobackupex --user= $BackupUser &Nbsp;--password= $BackupPassword --incremental --incremental-basedir= $FullBackupPath $weekofyear/$ newestfullbackup $IncreBackupPath $weekofyear 2>> $LogPath $weekofyear/incre_backup_$ date.log >> $LogPath $weekofyear/incre_backup_$date.logif [ $? -eq 0 ] then deletefielsenewestincrebackup= ' ls -t $IncreBackupPath $weekofyear | head -1 ' ### find newest incremental backupinnobackupex --user=$ backupuser --password= $BackupPassword --incremental --incremental-basedir= $IncreBackupPath $ weekofyear/$NewestIncreBackup $IncreBackupPath $weekofyear 2>> $LogPath $weekofyear/incre_ backup_$date.log >> $LogPath $weekofyear/incre_backup_$date.logif [ $? -eq 0 ] thendelete fifi
This article is from "Chalet Technology" blog, please make sure to keep this source http://starli.blog.51cto.com/8813574/1707393
MySQL database InnoDB storage Engine backup script