Monday, December 7, 2009

SQL Server database auto-backup done simply using windows scheduler

To accomplish database backup automatically just go through the following steps. However at first store the following script with sql extension e.g autobackup.sql in a disk drive.

DECLARE @MyBackupName nvarchar(250)
SET @MyBackupName = 'C:\Backup\YourDB' + convert( varchar(10), getdate(), 112 ) + '.BAK'
BACKUP DATABASE [YourDB] TO DISK = @MyBackupName
WITH
NOFORMAT,
NOINIT,
NAME = N'[YourDB]-Full Database Backup',
SKIP,
STATS = 10

Step 1. Go to control panel menu as Start->Settings->Control Panel.
Step 2. Now open the ‘Scheduled Tasks’ for scheduling purpose.
Step 3. Double click ‘Add Schedule Task’ and then click ‘Next’.
Step 4. Now browse for ‘SQLCMD.EXE’ file. (It can be found where SQL Server has been installed.)
Step 5. When it is ok type a name for this task.
Step 6. Then select the time and day you want this task to start.
Step 7. When it is ok click ‘Next’ then you must enter admin password.
Step 8. Just click ‘Finish’.
Step 9.
SQL SERVER 2005 EXPRESS EDITION:
When finished properly you will see "C:\Program Files\Microsoft SQL Server\90\Tools\Binn\SQLCMD.EXE" in the Run Text Box which is not sufficient at all. So replace "C:\Program Files\Microsoft SQL Server\90\Tools\Binn\SQLCMD.EXE" with "C:\Program Files\Microsoft SQL Server\90\Tools\Binn\SQLCMD.EXE" -SSALAHUDDIN\SQLEXPRESS -i"E:\autobackup.sql" in the Run Text Box.

SQL SERVER 2000 PERSONAL EDITION:
"C:\Program Files\Microsoft SQL Server\80\Tools\Binn\osql.exe" -SSALAHUDDIN -Usa -P123 -i"F:\autobackup.sql"

SALAHUDDIN is my server name. Your server name should simply replaces SALAHUDDIN.

Standard path format:[SQL Server 2005 Express and 2000 Personal Edition]
“SQLCMD.Exe path” –S[Server Name] –i[”autobackup.sql file path”]
“OSQL.Exe path” –S[Server Name] –Usa –P123 –i[”autobackup.sql file path”]

The path depends on as you have installed and stored SQL Server and autobackup.sql respectively.

No comments:

Post a Comment

Related Posts with Thumbnails