mysql备份脚本

 #!/bin/sh

account=root
password=f7m9g7fi
datadir=/var/lib/mysql
bakdir=/var/bak
mysqladmin -u$account -p$password flush-logs
total=`ls $datadir/mysql-bin.* |wc -l`
total="$(($total-2))"

for f in `ls $datadir/mysql-bin.* |head -$total`
do
mv $f $bakdir
done
cd $bakdir
for i in `ls `
do
if [ -f $i ]
then
var=${i##*.}
if [ $var == gz ]
then
continue
else
gzip -9 $i
fi
fi
done

你可能感兴趣的:(mysql备份脚本)