#!/bin/bash

DATE=`date +%F-%H-%M-%S`
mysqldump -uroot -p"123Abc.." wordpress > /mysql/bak/wordpress/wp-$DATE.sql
file_name=`ls -l /mysql/bak/wordpress/ | grep -v total | tail -1 | awk -F" " '{print $9}'`

if [ $? -eq 0 ];then
  echo "`date +%F`:$file_name:successful" >> /mysql/bak/wordpress/log/wp_bak.log
else
  echo "The wordpress sql is fails to backup,please check" >> /mysql/bak/wordpress/log/wp_bak_err.log
fi

file_num=`ls -l /mysql/bak/wordpress/*.sql | wc -l`
file_1=`ls -l /mysql/bak/wordpress/*.sql | grep -v total | head -1 | awk -F" " '{print $9}'`
if [ "$file_num" -gt 5 ];then
  rm -rf $file_1
fi
