自己写的一个很简单的mysql自动备份脚本
#!/bin/bash
#
# This program is used to backup the sql data of bugzilla.
# Johnny 20081226
#Variables:
DBName=
DBUser=
DBPass=
BackupPath=
DumpFile=db$(date +%Y%m%d).sql
OldFile=db$(date +%Y%m%d --date='4 weeks ago').sql
#Dump sql data
cd $BackupPath
mysqldump -u $DBUser -p$DBPass $DBName > $Dumpfile
#Delete old file
if [ -f $OldFile ]; then
rm -f $OldFile
echo "Delete Old File Success!"
else
echo "No Old Backup File!"
fi
最后crontab -e写入:
0 3 * * 7 sh backup.sh
实现每周日凌晨3点备份,只保留最近4周备份的功能。
阅读(677) | 评论(0) | 转发(0) |