touch 备份脚本名
#创建备份脚本
chmod +x 备份脚本名
#授予脚本执行权限
vim 备份脚本名
#!/usr/bin/bash
#Description:
#Author:
#Create time:
user=" "
password=" "
bak_time=`date +%Y%m%d`
bin_dir="/usr/local/mysql"
bin_file_idx="$bin_dir/mysql-bin.index"
bak_dir="/data/mysqlbak/increased_bak"
bak_log="$bak_dir/bak.log"
if [ ! -d $bak_dir ];then
mkdir -p $bak_dir
fi
if [ ! -f $bak_log ];then
touch $bak_log
fi
mysqladmin -u$user -p$password flush-logs
binlog_num=`wc -l $bin_file_idx |awk '{print $1}'`
num=0
for file in `cat $bin_file_idx`
do
base=`basename $file`
num=`expr $num + 1`
if [ $num -eq $binlog_num ]
then
echo "$base skip backup!" &>> $bak_log
else
dest=$bak_dir/$base
if(test -e $dest)
then
echo "$base exist!" &>> $bak_log
else
echo "$base copying!" &>> $bak_log
cp $bin_dir/$base $bak_dir
echo `date +"%Y%m%d %H:%M:%S"` $base increased_bak success!\n >> $bak_log
fi
fi
done