mysql物理级别热备脚本

 1 #!/bin/bash
 2 mysql_backup_dir=/data/databaseup/
 3 mysql_username="root"
 4 mysql_password="password"
 5 databasename="database1 database2"
 6 lastweek=$(date "+%y%m%d" -d "last week")
 7 timeStart=$(date '+%Y%m%d%H%M%S')
 8 dataname=${mysql_backup_dir}${timeStart}
 9 logfile=${mysql_backup_dir}/full-${timeStart}.log
10 
11 echo "开始备份..."`date`
12 innobackupex --user=$mysql_username --password=$mysql_password --defaults-file=/etc/my.cnf --database="$databasename" --no-lock --stream=xbstream --tmpdir=$mysql_backup_dir --sleep=200 --throttle=400 --compress --compress-threads=16 $mysql_backup_dir > ${dataname}.xbstream 2> "$logfile"
13 
14 mkdir -p ${dataname}
15 xbstream -x < ${dataname}.xbstream -C ${dataname}
16 innobackupex --decompress ${dataname} 2> "$logfile"
17 find ${dataname} -name "*.qp" | xargs rm -f
18 innobackupex --defaults-file=/etc/my.cnf --user=root --password=cff1981@wit --use-memory=4G --apply-log ${dataname} 2> "$logfile"
19 
20 echo "备份完毕..."`date`
21 
22 echo "删除老的备份..."`date`
23 
24 cd ${mysql_backup_dir} && ls|grep ${lastweek} |xargs rm -rf
25 
26 echo "删除老的备份完毕..."`date`

 

posted @ 2015-08-07 19:46  Martin2  阅读(339)  评论(0编辑  收藏  举报