@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=F:\backup\ rem 1按子目录保存备份文件;0不按 set lay_in_subfolder=1
: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 "sa" -S localhost -Q "backup database %dbname% to disk='%bakupfolder%%subfolder%%dbname%%stamp%.bak'" "C:\Program Files\WinRAR\RAR.exe" a -ep1 -r -o+ -m5 -s -df "%bakupfolder%%subfolder%%dbname%%stamp%".rar "%bakupfolder%%subfolder%%dbname%%stamp%.bak"