I WANT TO BACKUP SQL DB EVERY DAY 8PM

Posted by Nuwan under Sql Server on 5/2/2012 | Points: 10 | Views : 1768 | Status : [Member] | Replies : 6
DEAR ALL,
I want to backup my sql database every day 8.00 P.M Automatically,
How I configure that. Please help me.

Thank You.

Rathnayake


Responses

Posted by: Pandians on: 5/2/2012 [Member] [MVP] Silver | Points: 25

Up
0
Down
Use the script given below...

Change the DatabaseName, Backup File path as you required
USE [msdb]

GO
BEGIN TRANSACTION
DECLARE @ReturnCode INT
SELECT @ReturnCode = 0
IF NOT EXISTS (SELECT name FROM msdb.dbo.syscategories WHERE name=N'[Uncategorized (Local)]' AND category_class=1)
BEGIN
EXEC @ReturnCode = msdb.dbo.sp_add_category @class=N'JOB', @type=N'LOCAL', @name=N'[Uncategorized (Local)]'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback

END

DECLARE @jobId BINARY(16)
EXEC @ReturnCode = msdb.dbo.sp_add_job @job_name=N'Job Name',
@enabled=1,
@notify_level_eventlog=0,
@notify_level_email=0,
@notify_level_netsend=0,
@notify_level_page=0,
@delete_level=0,
@description=N'No description available.',
@category_name=N'[Uncategorized (Local)]',
@owner_login_name=N'sa', @job_id = @jobId OUTPUT
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'Step-I',
@step_id=1,
@cmdexec_success_code=0,
@on_success_action=1,
@on_success_step_id=0,
@on_fail_action=2,
@on_fail_step_id=0,
@retry_attempts=0,
@retry_interval=0,
@os_run_priority=0, @subsystem=N'TSQL',
@command=N'BACKUP DATABASE [DatabaseName] TO DISK = N''<BackupPath.Bak>''
WITH NOFORMAT,
INIT,
NAME = N''DatabaseName-Full Database Backup'',
SKIP, NOREWIND,
NOUNLOAD,
STATS = 10
GO
',
@database_name=N'master',
@flags=0
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_update_job @job_id = @jobId, @start_step_id = 1
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_add_jobschedule @job_id=@jobId, @name=N'Schedule-I',
@enabled=1,
@freq_type=4,
@freq_interval=1,
@freq_subday_type=1,
@freq_subday_interval=0,
@freq_relative_interval=0,
@freq_recurrence_factor=0,
@active_start_date=20120502,
@active_end_date=99991231,
@active_start_time=200000,
@active_end_time=235959,
@schedule_uid=N'5c6f7de5-3fa7-415a-8095-2be1b4340675'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_add_jobserver @job_id = @jobId, @server_name = N'(local)'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
COMMIT TRANSACTION
GOTO EndSave
QuitWithRollback:
IF (@@TRANCOUNT > 0) ROLLBACK TRANSACTION
EndSave:
GO


Cheers
www.SQLServerbuddy.blogspot.com
iLink Multitech Solutions

Nuwan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Savariya on: 5/2/2012 [Member] Starter | Points: 25

Up
0
Down
You can also set your scheduler in mysql administratator software and schedule take the backup schedule backup option are there in which you can also specify on which day u want to take bakcup and so many other parameters are also there

Nuwan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Pandians on: 5/2/2012 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi Nuwan

You asking about MYSQL (or) SQL SERVER ?

The script I have given for SQL Server !

Cheers
www.SQLServerbuddy.blogspot.com
iLink Multitech Solutions

Nuwan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 5/2/2012 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
He is asking about "SQL"

Here is another way of doing it
http://www.mssqltips.com/sqlservertip/1174/scheduling-backups-for-sql-server-2005-express/

Thank you for posting at Dotnetfunda
[Administrator]

Nuwan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nuwan on: 5/2/2012 [Member] Starter | Points: 25

Up
0
Down
I ask fir it SQl Server. I'll check this Great Reply.

thank you.

Rathnayake

Nuwan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sriramnandha on: 5/19/2012 [Member] Starter | Points: 25

Up
0
Down
U CAN USE JOB SCHEDULING TO FIX DATE AND TIME TO BACK UP YOUR DATABASE.

REGARDS

SRIRAM.R

sriram

Nuwan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response