Here, is the script that we used to take backup of all the MSSQL database present in the windows server. You would need to get the “Sa” password from any website web.config file.===============================
REM Created By Dhanasekaran
for /F “tokens=2-4 delims=/ ” %%A in (‘Date /T’) DO SET NowDate=%%A-%%B-%%C
echo %NowDate%
SET DBList=%SystemDrive%SQLDBList.txt
SqlCmd -S  .\SQLEXPRESS -U sa -P Password -Q “SET NoCount ON; SELECT Name FROM master.dbo.sysDatabases WHERE [Name] NOT IN (‘master’,’model’,’msdb’,’tempdb’)”> “%DBList%”
cd D:\Backup
mkdir D:\Backup\%NowDate%
FOR /F “tokens=*” %%I IN (%DBList%) DO (ECHO Backing up database: %%I
SqlCmd -S  .\SQLEXPRESS -U sa -P 27facil?ent -Q “BACKUP DATABASE [%%I] TO DISK=’D:\Backup\%NowDate%\%%I.bak'”
IF EXIST “%DBList%” DEL /F /Q “%DBList%”

Open notepad and save this file as “backup.bat” and then execute this file. The database backup will be stored in D:\Backup\Date.

1 thought on “Bacth script to take backup of all the database MSSQL”

Leave a Reply