把下面代碼復(fù)制粘貼到記事本上,保存為后綴為bat文件。
備份網(wǎng)站程序、MYSQL、MSSQL
@echo off REM - File: bkup.bat REM - Description: Restart's IIS (Web, FTP,MYSQL,MSSQL) REM - Author: databases back REM - ADD REM comments if you don't want to restart any REM - of Services echo ====================================================== echo 正在停止IIS、FTP、MYSQL、MSSQL等服務(wù)…… echo ====================================================== net stop "World Wide Web Publishing Service" net stop "IIS Admin Service" net stop "W3SVC" net stop "serv-u" net stop "MySQLa" net stop "SQLSERVERAGENT" net stop "MSSQLSERVER" echo ====================================================== echo 運(yùn)行備份,需要去掉echo保存即可! echo 正在備份MYSQL文件夾,請(qǐng)不要關(guān)閉窗口! ... echo ====================================================== Xcopy "d:\MySQL\data" "d:\bkup\mysql\" /e/I/d/h/r/y/q echo Xcopy "d:\MySQL\data" "d:\bkup\mysql\%date:~0,10%\data\" /e/I/d/h/r/y/q echo ====================================================== echo 正在備份MSSQL文件夾,請(qǐng)不要關(guān)閉窗口! ... Xcopy "d:\mssql" "d:\bkup\mssql\" /e/I/d/h/r/y/q echo Xcopy "d:\mssql" "d:\bkup\mssql\%date:~0,10%\data\" /e/I/d/h/r/y/q echo ====================================================== echo 正在備份網(wǎng)站程序,請(qǐng)不要關(guān)閉窗口! echo Xcopy "d:\wwwroot" "d:\bkup\web\" /e/I/d/h/r/y/q echo ====================================================== echo 正在啟動(dòng)IIS、FTP、MYSQL、MSSQL等服務(wù)…… echo ====================================================== net start "World Wide Web Publishing Service" net start "IIS Admin Service" net start "W3SVC" net start "serv-u" net start "MySQLa" net start "MSSQLSERVER" net start "SQLSERVERAGENT"
備份Access數(shù)據(jù)庫(kù),并打包壓縮文件,刪除N天前的文件。
@echo off echo ====================================================== echo 正在備份Access數(shù)據(jù)庫(kù)文件... 請(qǐng)不要關(guān)閉窗口! echo ====================================================== setlocal enabledelayedexpansion for /f "delims=" %%i in ('dir/a-d/s/b/l/on "d:\wwwroot\*.mdb"') do ( if /i "%%~nxi"=="shujukumingcheng.mdb" ( set "name_dp=%%~dpi" set "name_dp=!name_dp:d:\wwwroot\=e:\bkup\databases\!" xcopy/y "%%i" "!name_dp!" ) ) echo ====================================================== echo 完成數(shù)據(jù)庫(kù)備份!正在建立數(shù)據(jù)庫(kù)壓縮文件... 請(qǐng)不要關(guān)閉窗口! echo ====================================================== md "e:\bkup\package" "d:\Green\WinRAR\WinRAR.exe" a -ibck -m3 -agyyyy-mm-dd "e:\bkup\package\" "e:\bkup\databases" echo rd /s /q e:\bkup\databases echo ====================================================== echo 完成數(shù)據(jù)庫(kù)壓縮文件!正在刪除前七天的備份! echo ====================================================== forfiles /p e:\bkup\package /m *.rar -d -7 /c "cmd /c del /f @path"
備份數(shù)據(jù)到內(nèi)網(wǎng)主機(jī)
@echo off echo ====================================================== echo 備份數(shù)據(jù)到內(nèi)網(wǎng)主機(jī),連接登錄共享主機(jī)!******(修改為自己的密碼) echo ====================================================== net use \\192.168.1.2\ipc$ *******/user:administrator echo ====================================================== echo 正在備份網(wǎng)站程序! echo 請(qǐng)不要關(guān)閉窗口! echo ====================================================== xcopy "d:\Backup" "\\192.168.1.2\Backup" /e/I/d/h/r/y/q
自動(dòng)重啟服務(wù)器
@echo off echo ====================================================== echo 自動(dòng)重新啟動(dòng)(-r表示重啟,-f表示關(guān)閉未響應(yīng)程序,-t表示時(shí)間后面跟隨等待秒數(shù),0為馬上重啟) echo ====================================================== shutdown -r -f -t 0
提取當(dāng)前文件夾里面的文件名
@echo off dir *.*? /a-d /o:d /b >提取文件名.txt
建站咨詢熱線
029-33273980