mysql-linux定时备份mysql数据库

sh脚本

#!/bin/bash
db_user="数据库用户名"
db_passwd="数据库密码"
db_name="数据库名"
cd /进入备份文件目录/bakmysql
echo "you are in bakmysql directory now"
mv 备份文件名* /新的备份目录/bakmysqlold
echo "Old databases are moved to bakmysqlold folder"
backup_dir="/备份文件目录/bakmysql"
time=$(date +"%Y-%m-%d")
mysqldump -u$db_user -p$db_passwd $db_name  > "$backup_dir/$db_name"-"$time.sql"
echo "your database backup successfully completed"
SevenDays=$(date -d -30day  +"%Y-%m-%d")
if [ -f /备份文件目录/bakmysqlold/$db_name-$SevenDays.sql ]
then
rm -rf /备份文件目录/bakmysqlold/$db_name-$SevenDays.sql
echo "you have delete 30days ago bak sql file "
else
echo "30days ago bak sql file not exist "
echo "bash complete"
fi

 

posted @ 2018-04-25 08:42  243573295  阅读(620)  评论(0编辑  收藏  举报