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.
===============================
@ECHO OFF
SETLOCAL
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'"
ECHO.
)
IF EXIST "%DBList%" DEL /F /Q "%DBList%"
ENDLOCAL
===============================
Open notepad and save this file as "backup.bat" and then execute this file. The database backup will be stored in D:\Backup\Date.
===============================
@ECHO OFF
SETLOCAL
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'"
ECHO.
)
IF EXIST "%DBList%" DEL /F /Q "%DBList%"
ENDLOCAL
===============================
Open notepad and save this file as "backup.bat" and then execute this file. The database backup will be stored in D:\Backup\Date.
No comments:
Post a Comment