我的MySQL自动备份脚本
我写得脚本,每次备份我的MySQL数据库,就用下面的脚本完成。
/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*
@echo off
echo.
echo MySQL数据库备份
echo *****************************
echo.
echo 今天是 %date%
echo 时间是 %time%
echo.
echo *****************************
set "Ymd=%date:~,4%%date:~5,2%%date:~8,2%"
md "D:\JDBC\%Ymd%"
"C:\Program Files\MySQL\MySQL Server 5.1\bin\mysqldump" --opt -Q -uroot -pabc123 --default-character-set=latin1 test > "D:\JDBC\%Ymd%\test_bak.sql"
echo.
echo MySQL数据库备份完成,请进行检查。。。
echo.
echo.
pause
------解决方案--------------------
末学补充一个linux下的
[coolwind@localhost util]$ cat mysqlbackup.sh
#!/bin/bash
#################################
#
# Author coolwind
# Time 2009-06-11
# File mysqlbackup.sh
# Desc Backup MySQL data file
#
#################################
#Set the varible.
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
# Get the date messages and backup directory
backuptime=`date +%Y%m%d%H%M%S_%N`
backupdir=/mnt/backup/db/
backuppre=db_backup_
# MySQL infomation
HOST=127.0.0.1
PORT=3307
USER=root
#PASS=password
BACKUPDBFILE=$backupdir$backuppre$backuptime.sql
echo $BACKUPDBFILE
mysqldump -u$USER -h$HOST -P$PORT --all-databases --lock-all-tables --add-drop-database --add-drop-table --comments --complete-insert --default-character-set=utf8 --result-file=$BACKUPDBFILE
echo "$BACKUPDBFILE -> $BACKUPDBFILE.bz2"
bzip2 -z $BACKUPDBFILE
[coolwind@localhost util]$ crontab -l
#分 時 日 月 週 |<==============指令串========================>|
35 4 * * * /home/coolwind/util/mysqlbackup.sh >>/home/coolwind/util/logs/mysqlbackup.log 2>&1