MySQL Automatic scheduled backup

Source: Internet
Author: User
Tags rar

Description: The following is a database automatic backup script, which can be saved as a. bat, and then scheduled to be executed in a scheduled task.


:: Echo Database start Backup!


@echo off


:: Define Disk

Set Disk=d

:: Define unit name

Set UNIT=JD_SCJDJ

:: Define compressed file path

Set Rar=c:\program Files\winrar


:: Define the storage path

Set Filepath_ntdat=%disk%:\webserver\data_bak\ntdat

Set FILEPATH_NTCMS=%DISK%:\WEBSERVER\DATA_BAK\NTCMS_JD_SCJDJ

Set FILEPATH_NTLAS=%DISK%:\WEBSERVER\DATA_BAK\NTLAS_JD_SC

Set FILEPATH_NTLFS=%DISK%:\WEBSERVER\DATA_BAK\NTLFS_JD_SC

Set FILEPATH_NTPMS=%DISK%:\WEBSERVER\DATA_BAK\NTPMS_JD_SC

Set FILEPATH_NTREM=%DISK%:\WEBSERVER\DATA_BAK\NTREM_JD_SC

Set Filepath_pras=%disk%:\webserver\data_bak\pras

:: Define File types

Set Filetype=mysql

:: Define Time format

Set Datetime= "%date:~0,4%%date:~5,2%%date:~8,2%%time:~0,2%%time:~3,2%%time:~6,2%"

:: Define file name

Set filename_ntdat=ntdat_%unit%-%filetype%-%datetime%

Set filename_ntcms_jd_scjdj=ntcms_jd_scjdj_%unit%-%filetype%-%datetime%

Set filename_ntlas_jd_sc=ntlas_jd_sc_%unit%-%filetype%-%datetime%

Set filename_ntlfs_jd_sc=ntlfs_jd_sc_%unit%-%filetype%-%datetime%

Set filename_ntpms_jd_sc=ntpms_jd_sc_%unit%-%filetype%-%datetime%

Set filename_ntrem_jd_sc=ntrem_jd_sc_%unit%-%filetype%-%datetime%

Set filename_pras=pras_%unit%-%filetype%-%datetime%

:: Determine if a folder exists

If not Exist%filepath_ntdat% MD%filepath_ntdat%

If not Exist%filepath_ntcms% MD%filepath_ntcms%

If not Exist%filepath_ntlas% MD%filepath_ntlas%

If not Exist%filepath_ntlfs% MD%filepath_ntlfs%

If not Exist%filepath_ntpms% MD%filepath_ntpms%

If not Exist%filepath_ntrem% MD%filepath_ntrem%

If not Exist%filepath_pras% MD%filepath_pras%


:: Backing up the database

cd/d "%disk%:\webserver\tools\mysql_5.6.26\bin"

Mysqldump.exe--opt-u "root"--password= "root" "Ntdat" > "%filepath_ntdat%\ntdat.sql"

Mysqldump.exe--opt-u "root"--password= "root" "Ntcms" > "%filepath_ntcms%\ntcms_jd_scjdj.sql"

Mysqldump.exe--opt-u "root"--password= "root" "Ntlas" > "%filepath_ntlas%\ntlas_jd_sc.sql"

Mysqldump.exe--opt-u "root"--password= "root" "Ntlfs" > "%filepath_ntlfs%\ntlfs_jd_sc.sql"

Mysqldump.exe--opt-u "root"--password= "root" "Ntpms" > "%filepath_ntpms%\ntpms_jd_sc.sql"

Mysqldump.exe--opt-u "root"--password= "root" "Ntrem" > "%filepath_ntrem%\ntrem_jd_sc.sql"

Mysqldump.exe--opt-u "root"--password= "root" "Pras" > "%filepath_pras%\pras.sql"


:: Compress backup files

cd/d "%filepath_ntdat%"

"%rar%\winrar.exe" A "%filename_ntdat%.rar" "Ntdat.sql"

del/q "Ntdat.sql"

cd/d "%filepath_ntcms%"

"%rar%\winrar.exe" A "%filename_ntcms_jd_scjdj%.rar" "Ntcms_jd_scjdj.sql"

del/q "Ntcms_jd_scjdj.sql"

cd/d "%filepath_ntlas%"

"%rar%\winrar.exe" A "%filename_ntlas_jd_sc%.rar" "Ntlas_jd_sc.sql"

del/q "Ntlas_jd_sc.sql"

cd/d "%filepath_ntlfs%"

"%rar%\winrar.exe" A "%filename_ntlfs_jd_sc%.rar" "Ntlfs_jd_sc.sql"

del/q "Ntlfs_jd_sc.sql"

cd/d "%filepath_ntpms%"

"%rar%\winrar.exe" A "%filename_ntpms_jd_sc%.rar" "Ntpms_jd_sc.sql"

del/q "Ntpms_jd_sc.sql"

cd/d "%filepath_ntrem%"

"%rar%\winrar.exe" A "%filename_ntrem_jd_sc%.rar" "Ntrem_jd_sc.sql"

del/q "Ntrem_jd_sc.sql"

cd/d "%filepath_pras%"

"%rar%\winrar.exe" A "%filename_pras%.rar" "Pras.sql"

del/q "Pras.sql"

:: Echo Database End Backup!


This article is from the "Yang Hailong blog" blog, make sure to keep this source http://7218743.blog.51cto.com/7208743/1844513

MySQL Automatic scheduled backup

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.