壓縮備份資料庫與網站資料(mysql不停止的方法)簡易實用BAT
@echo off
::Author: jerry
::Date:2018-11-20
echo.
echo MySQL資料庫及網站程式備份指令碼
echo
echo Author: jerry
echo Date:2018-11-20
echo 備份日期:%date%
echo 備份時間:%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 正在進入MySQL目錄。注意:對於有空格的目錄,命令列要加引號。"C:\Program Files"
echo 正在備份Mysql資料,請稍等......
if not exist "%sqlcache%" mkdir "%sqlcache%"
for /F %%a 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=/" %%a in (dir /b %sqlcache%
echo 資料庫備份完成......
echo.
echo 網站資料備份中,請稍後......
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.