- 论坛徽章:
- 0
|
本帖最后由 狼毫吴钩 于 2011-06-02 18:59 编辑
我准备用crontab备份我的mysql,写了一个sh,直接运行时能正常备份,但是加到cron里,也能执行,备份出来的文件却是0字节,为什么呢?
我是用root用户登陆的服务器,cron里是这样写的:0 3 * * * /bin/sh /home/back_mysql.sh
补充一下:我的服务器系统是centos5.5
下面是我的sh
#!/bin/bash
#This is a ShellScript For Auto DB Backup
#Setting
DBName=mysqlqqq
DBUser=root
DBPasswd=mima
BackupPath=/home/backup
LogFile=/home/backup/log/bk_bugtracker.log
NewFile="$BackupPath/$DBName"_db_$(date +%Y_%m_%d).tgz
DumpFile="$BackupPath/$DBName"_db_$(date +%Y_%m_%d).sql
OldFile="$BackupPath/$DBName"_db_$(date +%Y_%m_%d --date='3 days ago').tgz
echo "-------------------------------------------">> $LogFile
echo $(date +"%Y-%m-%d %H:%M:%S")>> $LogFile
echo "--------------------------">> $LogFile
#Delete Old File
if [ -f $OldFile ]
then
rm -f $OldFile>> $LogFile 2>&1
echo "[$OldFile] Delete Old File Success!">> $LogFile
else
echo "[$OldFile] No Old Backup File!">> $LogFile
fi
#Create new backupfile
if [ -f $NewFile ]
then
echo "[$NewFile] The Backup File is exists,Can't Backup!">> $LogFile
else
mysqldump -u $DBUser -p$DBPasswd $DBName> $DumpFile
tar czvf $NewFile $DumpFile>> $LogFile 2>&1
echo "[$NewFile] Backup Success!">> $LogFile
rm -rf $DumpFile
fi
echo "-------------------------------------------">> $LogFile
echo>> $LogFile
echo>> $LogFile |
|