innobackupex定时全备,增量备份,压缩备份,自动同步到远程服务器脚本

全量:

#!/bin/bash  

 

mysql_backup_dir=/data/backup/mysql/

mysql_username="yours"  

mysql_password="YOURS"  

 

cd $mysql_backup_dir  

lastincrementfolder=`ls -l|grep ^d|tail -n 1 | awk '{print $9}'`  

timeStart=$(date '+%Y%m%d%H%M%S')  

logfile=full-$timeStart.log  

/usr/bin/innobackupex --user=$mysql_username  --no-lock --defaults-file=/etc/my.cnf  $mysql_backup_dir    2> "$logfile"

latestfolder=`ls -l|grep ^d|tail -n 1 | awk '{print $9}'`

tar -czvf /data/backup/mysql/full_$latestfolder.tar.gz -C /data/backup/mysql  ./$latestfolder

rsync -vzrtopg --progress --delete   --password-file=/etc/rsyncd.secrets /data/backup/mysql/ test@ip::test

 

 

增量:

#!/bin/bash  

 

mysql_backup_dir=/data/backup/mysql/

mysql_username="yours"  

mysql_password="YOURS"  

 

cd $mysql_backup_dir  

lastincrementfolder=`ls -l|grep ^d|tail -n 1 | awk '{print $9}'`  

timeStart=$(date '+%Y%m%d%H%M%S')  

logfile=increment-$timeStart.log  

/usr/bin/innobackupex --user=$mysql_username  --no-lock --defaults-file=/etc/my.cnf  --incremental  $mysql_backup_dir --incremental-basedir=$lastincrementfolder 2> "$logfile"

latestfolder=`ls -l|grep ^d|tail -n 1 | awk '{print $9}'`

tar -czvf /data/backup/mysql/increment_$latestfolder.tar.gz -C /data/backup/mysql  ./$latestfolder

rm -rf $latestfolder

rsync -vzrtopg --progress --delete   --password-file=/etc/rsyncd.secrets /data/backup/mysql/ test@ip::test

你可能感兴趣的:(backup)