- 论坛徽章:
- 0
|
- #!/usr/local/bin/bash
- # mysql_backup.sh: backup mysql databases and keep newest 10 days backup.
- # -----------------------------
- db_user="root"
- db_passwd="123456@321"
- db_host="localhost"
- # the directory for story your backup file.
- backup_dir="/home/www/.backupDB"
- # date format for backup file (dd-mm-yyyy)
- time="$(date +"%Y-%m-%d")"
- # mysql, mysqldump and some other bin's path
- MYSQL="$(which mysql)"
- MYSQLDUMP="$(which mysqldump)"
- MKDIR="$(which mkdir)"
- RM="$(which rm)"
- MV="$(which mv)"
- GZIP="$(which gzip)"
- # 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" && $MKDIR "$backup_dir"
- # get all databases
- for db in bbs www haosite cacti
- do
- $MYSQLDUMP -u $db_user -h $db_host -p$db_passwd $db | $GZIP -9 > "$backup_dir/$time.$db.gz"
- done
- #delete the oldest backup 10 days ago
- find $backup_dir -name "*.gz" -mtime +10 |xargs rm -rf
- exit 0;
复制代码 19 9 * * * www /home/www/.backupDB/backupDB.sh
这个多库备份脚本,直接执行是没有问题的,但是放在crontab里执行,只生成文件,但是没数据没有。
我的系统环境是BSD 8.2
特来请教大家。。。 |
|