时间:2021-07-01 10:21:17 帮助过:60人阅读
windows下,使用mssql命令行工具sqlcmd备份数据库,并调用rar压缩;不借助mssql维护计划功能,拜托权限问题。
1. set bakupfolder=F:\backup\
- <br>@ECHO ON <br>set d=%date:~0,10% <br>set d=%d:-=% <br>set t=%time:~0,8% <br>set t=%t::=% <br>set stamp=%p%%d%%t% <br>set bakupfolder=F:\backup\ <br>rem 1按子目录保存备份文件;0不按 <br>set lay_in_subfolder=1 <br>call :backupone foo <br>call :backupone foo2 <br>call :backupone foo3 <br>call :backupone foo4 <br>goto :EOF <br>@ECHO OFF <br>:backupone <br>setlocal <br>echo %1 <br>set dbname=%1 <br>if not exist %bakupfolder%%dbname% mkdir %bakupfolder%%dbname% <br>if %lay_in_subfolder%==1 ( <br>set subfolder=%dbname%\ <br>)else set subfolder= <br>rem echo %bakupfolder%%subfolder%%dbname%%stamp%.bak <br>sqlcmd -U sa -P "sa" -S localhost -Q "backup database %dbname% to disk='%bakupfolder%%subfolder%%dbname%%stamp%.bak'" <br>"C:\Program Files\WinRAR\RAR.exe" a -ep1 -r -o+ -m5 -s -df "%bakupfolder%%subfolder%%dbname%%stamp%".rar "%bakupfolder%%subfolder%%dbname%%stamp%.bak" <br>endlocal&goto :EOF