Example of automatic MySQL database backup and bat restoration

Source: Internet
Author: User
Tags ftp rar mysql database

Backup bat:

@ Set destfile = ICBC_mysql % date :~ 0, 4% % date :~ 5, 2% % date :~ 8, 2%. SQL
@ Set ftpfile = ICBC_mysql % date :~ 0, 4% % date :~ 5, 2% % date :~ 8, 22.16.rar
@ Echo: date: % date :~ 0, 4% % date :~ 5, 2% % date :~ 8, 2%
@ Echo backup file: % destfile %
@ F:
@ Cd \ bak_mis
@ Echo backing up ......
@ "C: \ Program Files \ MySQL Server 5.1 \ bin \ mysqldump.exe"-opt-uroot-p1234-P3306-all-databases> % destfile %
@ Echo start compression
@ "C: \ Program Files \ WinRAR \ Rar.exe" a-ed % ftpfile % destfile %
@ Del F: \ bak_mis \ % destfile %
@ Echo: The backup is complete and is being backed up to remote FTP ......
@ Echo user nmcx 185700> ftp.txt
@ Echo bin> ftp.txt
@ Echo put % ftpfile %> ftp.txt
@ Echo bye> ftp.txt

@ Ftp-I-n XXXX. XXXX <ftp.txt
@ Echo: The backup is successfully completed.

 

Restore bat:

 

@ Set destfile = ICBC_mysql % date :~ 0, 4% % date :~ 5, 2% % date :~ 8, 2%. SQL
@ Set ftpfile = ICBC_mysql % date :~ 0, 4% % date :~ 5, 2% % date :~ 8, 22.16.rar
@ Echo: date: % date :~ 0, 4% % date :~ 5, 2% % date :~ 8, 2%
@ Echo restore File: % destfile %
@ D:
@ Cd \ DB_bak

@ Echo is downloading files from remote FTP ......
@ Echo user nmcx 185700> ftp.txt
@ Echo bin> ftp.txt
@ Echo get % ftpfile %> ftp.txt
@ Echo bye> ftp.txt
@ Ftp-I-n XXXX. XXXX <ftp.txt

@ Echo start decompression
@ "C: \ Program Files \ WinRAR \ UnRAR.exe" e % ftpfile %

@ Echo is restoring the database ......
@ "D: \ MySQL Server 5.1 \ bin \ mysql.exe"-uroot-p1234-P3306 <D: \ DB_bak \ % destfile %

@ Del % destfile %

@ Echo: restored successfully

Note: (marked in red, the ftp user name, password, and ftp address respectively)

(In the purple part, the username, password, and port of the MySQL database respectively)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.