Take Backup of SQL Database Using Batch file

Step for Take Backup

1.Open Notepad

2.Paste following Code in notepad

3.Save this file as backup.bat

 Code snippets 

echo off
cls
echo -- BACKUP DATABASE --
set DATABASENAME=MobileRecharge

:: filename format Name-Date (eg MyDatabase-2009.5.19.bak)
set DATESTAMP=%DATE:~-4%.%DATE:~7,2%.%DATE:~4,2%
set BACKUPFILENAME=D:\%DATABASENAME%-%DATESTAMP%.bak
set SERVERNAME=DESKTOP-0BOTN0I\SQLEXPRESS
echo.

sqlcmd -E -S %SERVERNAME% -d master -Q "BACKUP DATABASE [%DATABASENAME%] TO DISK = N'%BACKUPFILENAME%' WITH INIT , NOUNLOAD , NAME = N'%DATABASENAME% backup', NOSKIP , STATS = 10, NOFORMAT"
echo.
pause



 Instruction 

1. MobileRecharge is database name replace this name with your database which you want to take backup

2. Here we specify D:/ for take backup

3.DESKTOP-0BOTN0I\SQLEXPRESS is server name replace with your server name

4.Run the file and see the backup in D:/ Drive

5.If you want to take backup Automatically Schedule this file in Task Scheduler(on Daily,Weekly or on Specific date time)
 

Comments

Popular posts from this blog

Create Short URL using C#