#!/bin/bash
PATH=/usr/local/sbin:/usr/bin:/bin
# The Directory of Backup
BACKDIR=/usr/mysql_backup
# The Password of MySQL
ROOTPASS=password
# Remake the Directory of Backup
rm -rf $BACKDIR
mkdir -p $BACKDIR
# Get the Name of Database
DBLIST=`ls -p /var/lib/mysql | grep / | tr -d /`
# 偷瞄了下我同事写脚本的方式,发现他直接将DBLIST一个个手动敲上去了
# 数据库少的情况是可以的,如果数据库是成百以上呢,呵呵
# Backup with Database
for dbname in $DBLIST
do
mysqlhotcopy $dbname -u root -p $ROOTPASS $BACKDIR | logger -t mysqlhotcopy
done许多系统管理员喜欢用mysqldump --opt来备份数据库,由于比较简单,我这里就不重复了。