[david_yeung@localhost ~]$ cat fast_backup #!/bin/sh## Created by david yeung.## 20080707.## Backup mysql's full data.#DBNAME=$1BACKUPDIR=/home/david_yeung/backup_newUSERNAME=backup_userPASSWD=123456TARNAME="$BACKUPDIR"/backup"$1"`date '+%Y%m%d'`# Add your own database name here.case "$1" in my_site);; *) exit;; esac# Get all the tables' name.NUM=`/usr/local/mysql/bin/mysql -u$USERNAME -p$PASSWD -s -vv -e "show tables" -D $DBNAME|wc -l`HEADNUM=`expr ${NUM} - 3`TAILNUM=`expr ${NUM} - 7`ARR1=`/usr/local/mysql/bin/mysql -u$USERNAME -p$PASSWD -s -vv -e "show tables" -D $DBNAME| head -n"$HEADNUM" | tail -n "$TAILNUM"`ARR2=($ARR1)i=0while [ "$i" -lt "${#ARR2[@]}" ]do tmpFileName=${ARR2[$i]} # The real dump process. /usr/local/mysql/bin/mysqldump -u$USERNAME -p"$PASSWD" "$DBNAME" "$tmpFileName" >> "$TARNAME" let "i++"done
2、因为我们一直用存储过程,所以得单独备份出来。
[david_yeung@localhost ~]$ cat fast_sp#!/bin/sh# Created by david yeung 20080122.## Backup site's routine.TARNAME=/home/david_yeung/backup_new/spBackup"$1"`date '+%Y%m%d'`/usr/local/mysql/bin/mysqldump -ubackup_user -p123456 -n -t -d -R my_site > "$TARNAME" 3、丢到计划任务里面去,就不管了。
[root@localhost backup_new]# crontab -l0 01 * * * /home/david_yeung/fast_backup my_site0 0 * * 5 /home/david_yeung/fast_sp 每天凌晨1点备份数据,每个周五凌晨备份存储过程。