- 代碼: 選擇全部
#!/bin/sh
# mysql_backup.sh: backup mysql databases at day
#updated: 5 Aug 2009
# ----------------------------------------------------------------------
# This is a free shell script under GNU GPL version 2.0 or above
# Copyright (C) 2009 Woff Lin
# Feedback/comment/suggestions : http://www.tshopping.com.tw
#--------------------------------------------------------
# your mysql login information
# db_user is mysql username
# db_passwd is mysql password
# db_host is mysql host
# -----------------------------
db_user="root"
db_passwd="xxxxx"
db_host="localhost"
# the directory for story your backup file.
backup_dir="/home/shihyu/mysql_backup"
# 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
all_db="$($MYSQL -u $db_user -h $db_host -p$db_passwd -Bse 'show databases')"
for db in $all_db
do
$MYSQLDUMP -u $db_user -h $db_host -p$db_passwd $db --skip-lock-tables | $GZIP -9 > "$backup_dir/mgtsql.$db.`date +%Y%m%d`.gz"
mutt -s "mgtsql.$db.`date +%Y%m%d`" xxxxxx@gmail.com -a "$backup_dir/mgtsql.$db.`date +%Y%m%d`.gz" < /home/shihyu/mysql_backup/test1
done
exit 0;
上面是我備份用的 shell srcipt code , 我在有兩台主機 , 都用上面同樣的程式去備份, 上面程式會幫我備份三個檔案 , 在寄到我mail 給我
但是其中一台常常備份寄到我信箱都只有2個檔案, 有一個檔案沒寄給我 , 但有時候三個檔案都會寄到信箱
但另一台主機都正常 , 請問這可能是什麼原因造成?
mutt -s "mgtsql.$db.`date +%Y%m%d`" xxxxxx@gmail.com -a "$backup_dir/mgtsql.$db.`date +%Y%m%d`.gz" < /home/shihyu/mysql_backup/test1 這行是我自己加上的原本這程式碼沒有~ 我是懷疑這邊有問題 , 因為我單純用 mutt 指令發送檔案都正常不會說有漏收
謝謝