备份mysql shell脚本

#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH

#!bin/sh
db_user=
db_passwd=
db_name=

# the directory for story your backup file.you shall change this dir
backup_dir="备份文件路径"

# date format for backup file (dd-mm-yyyy)
# 以时间命名备份数据库 time="$(date +"%Y%m%d%H%M%S")"
createAt=date +%Y-%m-%d-%H:%M:%S
mysqldump -u$db_user -p$db_passwd $db_name > "$backup_dir/$db_name"_"$time.sql"

cd /www/wwwroot/blog //Git操作
git add .
git commit -m $time
git push

#删除七天之前的备份
find $backup_dir -name $db_name"*.sql" -type f -mtime +7 -exec rm -rf {} ; > /dev/null 2>&1

#删除一分钟之前的备份
#find $backup_dir -name $db_name"*.sql" -type f -mmin +1 -exec rm -rf {} ; > /dev/null 2>&1

鹿晓鹏博客
请先登录后发表评论
  • latest comments
  • 总共0条评论