Step 3: How to automatically back up mysql databases with one click

Source: Internet
Author: User

Backing up mysql has always been a headache for many friends, especially by time period. Today I will teach you how to back up mysql database files with one click every day using graphic tutorials.

1. Create a batch file and save the following code as a. bat file. The file name should be in English. Note the following path. Take the author's own database as an example. The database is installed in MySQL under drive d, and the backup location is F: beifen, followed by the date code.

@ Echo off

Color 0D

MODE con: COLS = 71 LINES = 25

Title mysql database automatic backup script (Task Plan) -- script author: http: // www. ****. com

Set sou_dir = "D: mysqlMysqldata"

Set obj_dir = F: beifen % date :~ 0, 10%

Net stop mysql

Md % obj_dir %

Xcopy/e/y % sou_dir % obj_dir %

Net start mysql

@ Echo off & setlocal enabledelayedexpansion

Call: D, 30

Echo. 30 days ago: % D %

Echo. Delete backups 30 days ago ......

If exist F: beifen % D % rd/s/q F: beifen % D %

Echo automatic backup is complete, and the program will automatically exit ......

Ping-n 2 127.0.0> nul

Exit

: D

For/f "tokens = 1-3 delims =-:/" % a in ("% date %") do (

Set Y = % a & set M = % B & set D = % c

If "! M :~ 0, 1! "=" 0 "set M =! M :~ 1!

If "! D :~ 0, 1! "=" 0 "set D =! D :~ 1!

)

Set/a D-= % 1

If % D % gtr 0 goto: Y

: M

Set/a M-= 1

If! M! = 0 set/a Y-= 1, M = 12

Set/a "T = ^! (M-2) "," R = (^! (Y % 4) & ^! ^! (Y % 100) | ^! (Y % 400) "," C = ^! M-4 | ^! M-6 | ^! M-9 | ^! (M-11) "," D = T * (28 + R) + C * 30 + (^! T & ^! C)

* 31 + D"

If % D % leq 0 goto: M

: Y

Set M = 0% M % & set D = 0% D % & set D = % Y % -! M :~ -2! -! D :~ -2!

2. Create a scheduled task that can be backed up every day or three days or even longer. mysql stops automatically during Backup and starts automatically after the backup is complete. Open Control Panel --- double-click the task scheduler and select the scheduler step by step as prompted, as shown in:

  

 

3. We can set daily, weekly, or other dates to regularly back up mysql databases as needed. The experiment has completely met our daily mysql database backup needs.

  

This original self-road rice network http://www.45fan.com, reproduced need to indicate the source!

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.