windows 批处理 备份SQL数据 并且创建压缩文件
@ECHO ON set d=%date:~0,10% set d=%d:-=% set t=%time:~0,8% set t=%t::=% set stamp=%p%%d%%t% set bakupfolder=E:\BackDB_DongLin\ rem 1按子目录保存备份文件;0不按 set lay_in_subfolder=0 call :backupone DB_DongLin goto :EOF @ECHO OFF :backupone setlocal echo %1 set dbname=%1 if not exist %bakupfolder%%dbname% mkdir %bakupfolder%%dbname% if %lay_in_subfolder%==1 ( set subfolder=%dbname%\ )else set subfolder= rem echo %bakupfolder%%subfolder%%dbname%%stamp%.bak sqlcmd -U sa -P "qazwsx123,." -S .\MSSQL2005 -Q "backup database %dbname% to disk='%bakupfolder%%subfolder%%dbname%%stamp%.bak'" "E:\Program Files\WinRAR\RAR.exe" a -ep1 -r -o+ -m5 -s -df "%bakupfolder%%subfolder%%dbname%%stamp%".rar "%bakupfolder%%subfolder%%dbname%%stamp%.bak" pause endlocal&goto :EOF
可利用 百度网盘实现自动备份 可确保数据万无一失