码迷,mamicode.com
首页 > 数据库 > 详细

SHELL脚本自动备份数据库

时间:2018-03-22 19:21:07      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:date   格式   mysql   shell脚本   db_name   back   direct   seve   echo   

#!/bin/bash
db_user="root"
db_passwd="dddddd "
db_name="mmmmmm"

cd /db_backup
echo "you are in bakmysql directory now"

backup_dir="/db_backup"

#时间格式
time=$(date+ "%Y+%m+%d")
#mysql备份命令
mysqldump -u$db_user -p$db_passwd $db_name > "$backup_dir/$db_name"-"$time.dump"
echo "your database backup successfully completed"

#删除7天前的备份文件
SevenDays=$(date -d -7days +"%Y%m%d")
if [ -f /db_backup/ebkcmp-$SevenDays.dump]
then
rm -rf /db_backup/ebkcmp-$SevenDays.dump
echo "you have delete the sql file"
else
echo "the sql file not exits"
echo "bash completed"
fi

  

SHELL脚本自动备份数据库

标签:date   格式   mysql   shell脚本   db_name   back   direct   seve   echo   

原文地址:https://www.cnblogs.com/peteremperor/p/8625405.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!