常见问题常见问题   搜索搜索   会员列表会员列表   团队团队   注册注册    个人资料个人资料   登录查看您的站内信件登录查看您的站内信件   登录登录 

crontab执行mysql备份,但是没有生成备份文件

 
发表新文章   回复文章    FreeBSD China -> 技术交流
阅读上一个主题 :: 阅读下一个主题  
作者 留言
litiger
半仙


注册时间: 2007-01-21
文章: 66

文章发表于: Thu 2016-07-28 08:46:10    发表主题: crontab执行mysql备份,但是没有生成备份文件 引用并回复

我配置定时执行任务备份mysql,在命令行执行能正常备份,但是放在crontab后,却没有备份,看日志crontab是正常执行了脚本的,也没有错误提示,

crontab加的
15 8 * * * root /home/mysqlbackup/mysqlbackup.sh

mysqlbackup.sh内容
#!/bin/sh
db_user="tiger"
db_passwd="tiger"
db_host="localhost"

# directory for backup files.
backup_dir="/home/mysqlbackup"

# delete backup files created expdays ago
expdays=100

# date format for backup files (yyyy-mm-dd)
time="$(date +"%Y-%m-%d")"

# a comma delimited list of databases to backup, backup all databases if blank
dblist="tiger"

# get full path and name for the following programs
MYSQL="$(which mysql)"
if [ -z $MYSQL ]; then
echo "mysql not found ..."
exit 0
fi
MYSQLDUMP="$(which mysqldump)"
if [ -z $MYSQLDUMP ]; then
echo "mysqldump not found ..."
exit 0
fi
MKDIR="$(which mkdir)"
RM="$(which rm)"
GZIP="$(which gzip)"
###########END-USER-DEFINE###########

# create backup root directory if not found
test ! -d "$backup_dir/" && $MKDIR "$backup_dir/"

# check the directory for store backup is writeable
test ! -w $backup_dir && echo "Error: $backup_dir is un-writeable." && exit 0

# the directory for story the newest backup
test ! -d "$backup_dir/$time/" && $MKDIR "$backup_dir/$time/"

# get all databases
all_db="$($MYSQL -u $db_user -h $db_host -p$db_passwd -Bse 'show databases')"

for db in $all_db
do
goforit=$db
if [ ! -z "$dblist" ]; then
goforit=`echo ",$dblist," |grep ",$db,"`
fi
if [ ! -z "$goforit" ]; then
$MYSQLDUMP -u $db_user -h $db_host -p$db_passwd $db | $GZIP -9 > "$backup_dir/$time/$time.$db.gz"
fi
done

# delete the oldest backup
find $backup_dir -type d -mtime +$expdays -maxdepth 1 | xargs $RM -rf

log记录
Jul 28 08:15:00 server2 /usr/sbin/cron[7088]: (root) CMD (/home/mysqlbackup/mysqlbackup.sh)


最后进行编辑的是 litiger on Mon 2016-08-01 08:11:26, 总计第 1 次编辑
返回页首
阅览会员资料 发送站内信件
litiger
半仙


注册时间: 2007-01-21
文章: 66

文章发表于: Thu 2016-07-28 08:48:16    发表主题: 引用并回复

系统是freebsd10 64位!
返回页首
阅览会员资料 发送站内信件
从以前的文章开始显示:   
发表新文章   回复文章    FreeBSD China -> 技术交流 论坛时间为 北京时间
1页/共1

 
转跳到:  
不能发布新主题
不能在这个论坛回复主题
不能在这个论坛编辑自己的文章
不能在这个论坛删除自己的文章
不能在这个论坛发表投票


Powered by phpBB 2023cc © 2003 Opensource Steps; © 2003-2009 The FreeBSD Simplified Chinese Project
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Project Honey Pot and phpBB.cc
silvery-trainer
The FreeBSD China Project 网站: 中文计划网站 社区网站
The FreeBSD China Project 版权所有 (C) 1999 - 2003 网页设计版权 著作权和商标