mysql定期备份 #!/bin/sh # System + MySQL backup script # Full backup day - Sun (rest of the day do incremental backup) # Copyright (c) 2005-2006 nixCraft <http://www.cyberciti.biz/fb/> # This script is licensed under GNU GPL version 2.0 or above # Automatically generated by # http://bash.cyberciti.biz/backup/wizard-ftp-script.php # --------------------------------------------------------------------- ### System Setup ### ##备份本件本地目录## DIRS="/home/xxxx" BACKUP=/tmp/backup.$$ ##日期格式 可以自己调节## NOW=$(date +"%Y-%m-%d") INCFILE="/home/xxxx" DAY=$(date +"%u") ##星期天完全备份 可以自己调节## FULLBACKUP="7" ### MySQL Setup ### MUSER="chaos" MPASS="password" MHOST="host" MYSQL="$(which mysql)" MYSQLDUMP="$(which mysqldump)" GZIP="$(which gzip)" ### FTP server Setup ### ##增量备份路径## FTPD="/backup/xxxx/incremental" FTPU="chaos" FTPP="password" FTPS="xxx.xxx.com" ### Other stuff ### EMAILID="[email protected]" ### Start Backup for file system ### [ ! -d $BACKUP ] && mkdir -p $BACKUP || : ### See if we want to make a full backup ### if [ "$DAY" == "$FULLBACKUP" ]; then ##完全备份路径## FTPD="/backup/xxxx/full" FILE="fs-full-$NOW.tar.gz" tar -zcvf $BACKUP/$FILE $DIRS else i=$(date +"%Hh%Mm%Ss") FILE="fs-i-$NOW-$i.tar.gz" tar -g $INCFILE -zcvf $BACKUP/$FILE $DIRS fi ### Start MySQL Backup ### # Get all databases name ##备份所有数据库 可自行调整 或备份指定数据库## DBS="$($MYSQL -u $MUSER -h $MHOST -p$MPASS -Bse 'show databases')" for db in $DBS do FILE=$BACKUP/mysql-$db.$NOW-$(date +"%T").gz $MYSQLDUMP -u $MUSER -h $MHOST -p$MPASS $db | $GZIP -9 > $FILE done ### Dump backup using FTP ### #Start FTP backup using lftp ##ubuntu上可以使用ncftp 自行调节## #ncftp -u"$FTPU" -p"$FTPP" $FTPS<<EOF lftp -u $FTPU,$FTPP $FTPS<<EOF mkdir $FTPD mkdir $FTPD/$NOW cd $FTPD/$NOW lcd $BACKUP mput * quit EOF ### Find out if ftp backup failed or not ### if [ "$?" == "0" ]; then rm -f $BACKUP/* else T=/tmp/backup.fail echo "Date: $(date)">$T echo "Hostname: $(hostname)" >>$T echo "Backup failed" >>$T mail -s "BACKUP FAILED" "$EMAILID" <$T rm -f $T fi
#!/bin/sh
# System + MySQL backup script
# Full backup day - Sun (rest of the day do incremental backup)
# Copyright (c) 2005-2006 nixCraft <http://www.cyberciti.biz/fb/>
# This script is licensed under GNU GPL version 2.0 or above
# Automatically generated by
# http://bash.cyberciti.biz/backup/wizard-ftp-script.php
# ---------------------------------------------------------------------
### System Setup ###
##备份本件本地目录##
DIRS="/home/xxxx"
BACKUP=/tmp/backup.$$
##日期格式 可以自己调节##
NOW=$(date +"%Y-%m-%d")
INCFILE="/home/xxxx"
DAY=$(date +"%u")
##星期天完全备份 可以自己调节##
FULLBACKUP="7"
### MySQL Setup ###
MUSER="chaos"
MPASS="password"
MHOST="host"
MYSQL="$(which mysql)"
MYSQLDUMP="$(which mysqldump)"
GZIP="$(which gzip)"
### FTP server Setup ###
##增量备份路径##
FTPD="/backup/xxxx/incremental"
FTPU="chaos"
FTPP="password"
FTPS="xxx.xxx.com"
### Other stuff ###
EMAILID="[email protected]"
### Start Backup for file system ###
[ ! -d $BACKUP ] && mkdir -p $BACKUP || :
### See if we want to make a full backup ###
if [ "$DAY" == "$FULLBACKUP" ]; then
##完全备份路径##
FTPD="/backup/xxxx/full"
FILE="fs-full-$NOW.tar.gz"
tar -zcvf $BACKUP/$FILE $DIRS
else
i=$(date +"%Hh%Mm%Ss")
FILE="fs-i-$NOW-$i.tar.gz"
tar -g $INCFILE -zcvf $BACKUP/$FILE $DIRS
fi
### Start MySQL Backup ###
# Get all databases name
##备份所有数据库 可自行调整 或备份指定数据库##
DBS="$($MYSQL -u $MUSER -h $MHOST -p$MPASS -Bse 'show databases')"
for db in $DBS
do
FILE=$BACKUP/mysql-$db.$NOW-$(date +"%T").gz
$MYSQLDUMP -u $MUSER -h $MHOST -p$MPASS $db | $GZIP -9 > $FILE
done
### Dump backup using FTP ###
#Start FTP backup using lftp
##ubuntu上可以使用ncftp 自行调节##
#ncftp -u"$FTPU" -p"$FTPP" $FTPS<<EOF
lftp -u $FTPU,$FTPP $FTPS<<EOF
mkdir $FTPD
mkdir $FTPD/$NOW
cd $FTPD/$NOW
lcd $BACKUP
mput *
quit
EOF
### Find out if ftp backup failed or not ###
if [ "$?" == "0" ]; then
rm -f $BACKUP/*
else
T=/tmp/backup.fail
echo "Date: $(date)">$T
echo "Hostname: $(hostname)" >>$T
echo "Backup failed" >>$T
mail -s "BACKUP FAILED" "$EMAILID" <$T
rm -f $T
fi
c:
mysqldump -F --opt -uroot -p123456 -h 192.168.3.6 dbname > d:\backup.sql
"C:\Program Files\WinRAR\Rar.exe" m -ag -inul d:\backup.rar "d:\backup.sql"[/code]引用ASDFGHJKL987 的
http://topic.csdn.net/u/20090504/09/0477b467-bc49-4e50-a9e7-9ee2337ab0e1.html