/* ==Scripting Parameters== Source Server Version : SQL Server 2016 (13.0.1601)
Source Database Engine Edition : Microsoft SQL Server Enterprise Edition
Source Database Engine Type : Standalone SQL Server Target Server Version : SQL Server 2016
Target Database Engine Edition : Microsoft SQL Server Enterprise Edition
Target Database Engine Type : Standalone SQL Server
*/ USE [msdb]
GO /****** Object: Job [FullBackup] Script Date: 9/11/2017 7:50:54 PM ******/
BEGIN TRANSACTION
DECLARE @ReturnCode INT
SELECT @ReturnCode = 0
/****** Object: JobCategory [[Uncategorized (Local)]] Script Date: 9/11/2017 7:50:54 PM ******/
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'FullBackup',
@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'CLOUD-88\Administrator', @job_id = @jobId OUTPUT
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
/****** Object: Step [FullBackup] Script Date: 9/11/2017 7:50:54 PM ******/
EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'FullBackup',
@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 [master] TO DISK = N''\\SQL-AGBACKUP\AG\master.bak'' WITH COPY_ONLY, NOFORMAT, NOINIT, NAME = N''master_backup'', SKIP, REWIND, NOUNLOAD, STATS = 10
GO
BACKUP DATABASE [model] TO DISK = N''\\SQL-AGBACKUP\AG\model.bak'' WITH COPY_ONLY, NOFORMAT, NOINIT, NAME = N''model_backup'', SKIP, REWIND, NOUNLOAD, STATS = 10
GO
BACKUP DATABASE [msdb] TO DISK = N''\\SQL-AGBACKUP\AG\msdb.bak'' WITH COPY_ONLY, NOFORMAT, NOINIT, NAME = N''msdb_backup'', SKIP, REWIND, NOUNLOAD, STATS = 10
GO
DECLARE @preferredReplica int SET @preferredReplica = (SELECT [master].sys.fn_hadr_backup_is_preferred_replica(''OnlineLoansCommon'')) IF (@preferredReplica = 1)
BEGIN
BACKUP DATABASE [OnlineLoansCommon] TO DISK = N''\\SQL-AGBACKUP\AG\OnlineLoansCommon.bak'' WITH COPY_ONLY, NOFORMAT, NOINIT, NAME = N''OnlineLoansCommon'', SKIP, REWIND, NOUNLOAD, STATS = 10
END
GO
DECLARE @preferredReplica int SET @preferredReplica = (SELECT [master].sys.fn_hadr_backup_is_preferred_replica(''OnlineLoansCommonQA'')) IF (@preferredReplica = 1)
BEGIN
BACKUP DATABASE [OnlineLoansCommonQA] TO DISK = N''\\SQL-AGBACKUP\AG\OnlineLoansCommonQA.bak'' WITH COPY_ONLY, NOFORMAT, NOINIT, NAME = N''OnlineLoansCommonQA'', SKIP, REWIND, NOUNLOAD, STATS = 10
END
',
@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_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