转自:https://blog.csdn.net/lwei_998/article/details/7346001
功能:用mysqldump备份windows 下的MySql,并上传到ftp服务器
用法:1. 将下述脚本保存为bat文件,如backup.bat
2. 通过windows的定时任务来调用backup.bat
- cd D:
- cd D:\DB_Backup\2012
- echo 设置MySql数据库的IP
- set ipaddress=192.168.0.100
- echo 设置MySql数据库名
- set db_name1=test_db
- echo 获取当天的日期格式yyyymmdd 20120311
- set backup_date=%date:~0,4%%date:~5,2%%date:~8,2%
- set backup_date1=date:~0,10
- echo 获取前两天的日期
- set /A del_zip_file= %date:~0,4%%date:~5,2%%date:~8,2%-2
- echo 设置mysqldump 备份的参数
- set uid_test_db=-uroot -pmysql -h %ipaddress% %db_name1%
- echo 使用mysqldump对指定的MySql进行备份
- mysqldump %uid_test_db% >MYSQL_100_%backup_date%_%db_name1%.sql
- echo 用7-zip对备份出的sql文件进行压缩,此处使用7zip进行压缩,也可以换成其它的压缩命令
- 7z a MYSQL_100_%backup_date%.zip *.sql
- echo 删除已压缩的备份文件
- del MYSQL_100_*.sql
- echo 生成ftp的参数文件,把压缩后的zip文件上传到FTP服务器
- rem begin put today backupfiel to ftp server
- echo open 192.168.0.200>>temp.txt
- echo user ftpuser>>temp.txt
- echo ftppassword>>temp.txt
- echo cd MySQL\201203 >>temp.txt
- echo put MYSQL_100_%backup_date%.zip >>temp.txt
- echo bye >>temp.txt
- echo 执行上传命令
- ftp -i -n -s:temp.txt
- echo 删除ftp的临时参数文件
- rem delete temp.txt
- del temp.txt
- rem end put today backupfiel to ftp server
- rem begin delete yesterday backup
- 删除两天前备份的压缩文件
- del MYSQL_100_%del_zip_file%.zip
- rem end delete yesterday backup