Use psexec to back up all sql servers DB remotely.



Rem cmd /V:ON
@echo off

Rem clean screen
cls

set ExecuteCMD=PsExec
set Credential=-u mrscale\tv2bot -p Esoteric$
set SQLCMDPath="C:\Program Files\Microsoft SQL Server\100\Tools\Binn\SQLCMD.EXE"
Rem input XXX of BranchDB_XXX.bak
set /p DBBackupName=Input the backup name :

Rem tb6-bdb-01 part
echo.
echo Backup the BranchDB on tb6-bdb-01...
Rem Set the command to variable
set cmd=%ExecuteCMD% \\TB-BDB-01 %Credential% %SQLCMDPath% -Q "BACKUP DATABASE BranchDB To disk='T:\GrantsTesting\BranchDB_%DBBackupName%.bak'"
Rem execute the command
call %cmd%

Rem tb6-sg1db-01 part
echo.
echo Backup the ServiceGroupDB on tb6-sg1db-01...
Rem Set the command to variable
set cmd=%ExecuteCMD% \\TB-SGDB-01 %Credential% %SQLCMDPath% -Q "BACKUP DATABASE ServiceGroupDB To disk='T:\GrantsTesting\ServiceGroupDB_%DBBackupName%.bak'"
Rem execute the command
call %cmd%

Rem MDS4-DB-01 part
echo.
echo Backup the CommonDB on MDS4-DB-01...
Rem Set the command to variable
set cmd=%ExecuteCMD% \\AMDS-DB-01 %Credential% %SQLCMDPath% -Q "BACKUP DATABASE CommonDB To disk='P:\GrantsTesting\CommonDB_%DBBackupName%.bak'"
Rem execute the command
call %cmd%

pause

你可能感兴趣的:(Use psexec to back up all sql servers DB remotely.)