Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Compress backup database and website data (mysql non-stop method) simple and practical BAT

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

As the MySQL backup on the company's windows server has not used a third-party hot backup tool, the backup method is still to directly stop Mysql for database file COPY backup in the early morning of LOW (BAT script). Recently, the customer reported that the website could not be opened intermittently, affecting the access experience, so it needed to be rectified, so I downloaded a three-party tool to back up and set up a regular backup. The test found that its so-called compression hot standby method (looks very lofty, really easy to set up), in fact, copies the database files to a temporary directory, then compresses and stores them and deletes the temporary directory files, resulting in writing a BAT script instead of installing this tool (you can also be lazy). The planned tasks are all set, and you can replace the original script that compares LOW, and there is no need to change other task configurations. Plus the installation of backup each also need a little bit, more servers, so wrote the following script: time-tight script can also be optimized and improved, do not spray!

@ echo off

:: Author: jerry

Date:2018-11-20

Echo.

Backup script of echo MySQL database and website program

Echo

Echo Author: jerry

Echo Date:2018-11-20

Echo backup date:% date%

Echo backup time:% time%

Echo.

Echo

Set "Ymd=%date:~,4%%date:~5,2%%date:~8,2%"

Set bakdir= "D:\ Program Files\ MySQL51\ data"

Set sqlcache= "C:\ mysqlcache"

Set webdir= "E:\ wwwroot"

Echo is entering the MySQL directory. Note: for directories with spaces, put quotation marks on the command line. "C:\ Program Files"

Echo is backing up Mysql data. Please wait a moment.

If not exist "sqlcache%" mkdir "sqlcache%"

For / F% an in ('dir / ad / b% bakdir%') do (

:: echo "% bakdir%\% a% sqlcache%\% a" > > a.log

If not exist "% sqlcache%\% a" mkdir "% sqlcache%\% a"

Xcopy "D:\ Program Files\ MySQL51\ data"\% a "C:\ mysqlcache"\% a / s / E / y > nul

)

If not exist "F:\ mysqlbak\% Ymd%" mkdir "F:\ mysqlbak\% Ymd%"

For / f "usebackq tokens=1 delims=/"% an in (dir / b% sqlcache%) do "C:\ Program Files (x86)\ WinRAR\ WinRAR.exe" a-ep1-R0-df-exit-"F:\ mysqlbak\% Ymd%\% a.rar"% sqlcache%\% a

Echo database backup completed.

Echo.

Echo website data backup, please wait.

If not exist "F:\ freehostbackup\% Ymd%" mkdir "F:\ freehostbackup\% Ymd%"

For / f "usebackq tokens=1 delims=/"% I in (dir / b% webdir%) do "C:\ Program Files (x86)\ WinRAR\ WinRAR.exe" a-ep1-R0-exit-"F:\ freehostbackup\% Ymd%\% i.rar"% webdir%\% I

Echo.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report