Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
mssql_log_shipping [2020/03/10 14:23] – andonovj | mssql_log_shipping [2020/03/10 23:18] (current) – andonovj | ||
---|---|---|---|
Line 4: | Line 4: | ||
{{ : | {{ : | ||
- | |||
- | |||
There are couple things which has to be configured: | There are couple things which has to be configured: | ||
Line 11: | Line 9: | ||
[[mssql_log_shipping_primary|On Primary]] | [[mssql_log_shipping_primary|On Primary]] | ||
+ | * Disable Current Transaction Log Backup | ||
* Create a schedule | * Create a schedule | ||
* Create the necessary jobs and attach them Schedule | * Create the necessary jobs and attach them Schedule | ||
Line 21: | Line 20: | ||
* Restore the backup done on the primary | * Restore the backup done on the primary | ||
* Start the log-shipping | * Start the log-shipping | ||
- | * * In case edit the job if needed | ||
- | |||
- | |||
- | |||
- | ======Configure Secondary Server====== | ||
- | Once all the backups and the configurations on the primary have been done, it is time to configure the secondary. Bear in mind that the secondary server SHOULD have access to the shared location or the backup should reside on the secondary server itself. | ||
- | |||
- | |||
- | =====Create Schedules===== | ||
- | We need 2 types of schedules for the log shipping configuration: | ||
- | |||
- | * Copy Schedule | ||
- | * Restore Schedule | ||
- | |||
- | |||
- | ====Copy schedule==== | ||
- | The purpose of the copy schedule is to copy the log backup, performed by the primary server job, to the secondary server: | ||
- | |||
- | Like with the primary server schedule, we can use the same settings: | ||
- | |||
- | <sxh bash> | ||
- | EXEC sp_add_schedule | ||
- | @schedule_name = N' | ||
- | @freq_type=4, | ||
- | @freq_interval=1, | ||
- | @freq_subday_type=4, | ||
- | @freq_subday_interval=5, | ||
- | @active_start_time=000000, | ||
- | @active_end_time=235959 ; | ||
- | </ | ||
- | |||
- | |||
- | ====Restore Schedule==== | ||
- | The restore schedule and job are little bit specific, especially the job, since it depends if we will use the log restore as standby or as norecovery, as we are going to see later. The command for the schedule is more or less the same as the previous ones: | ||
- | |||
- | |||
- | <sxh bash> | ||
- | EXEC sp_add_schedule | ||
- | @schedule_name = N' | ||
- | @freq_type=4, | ||
- | @freq_interval=1, | ||
- | @freq_subday_type=4, | ||
- | @freq_subday_interval=5, | ||
- | @active_start_time=000000, | ||
- | @active_end_time=235959 ; | ||
- | </ | ||
- | |||
- | |||
- | =====Restore===== | ||
- | Once the schedules are created, we can proceed and restore: | ||
- | |||
- | <sxh bash> | ||
- | xp_cmdshell N' | ||
- | GO | ||
- | xp_cmdshell N' | ||
- | GO | ||
- | xp_cmdshell N' | ||
- | GO | ||
- | |||
- | RESTORE DATABASE [casino] | ||
- | FROM DISK = N' | ||
- | WITH FILE = 1, | ||
- | MOVE N' | ||
- | MOVE N' | ||
- | MOVE N' | ||
- | MOVE N' | ||
- | MOVE N' | ||
- | MOVE N' | ||
- | STANDBY = N' | ||
- | --NORECOVERY if NEWER VERSION | ||
- | GO | ||
- | </ | ||
- | |||
- | Nice that for newer version, for example SQL2008 -> SQL2016 we have to use NORECOVERY instead of Standby. | ||
- | After the backup completes, it will not open the database and the database will appear as " | ||
- | |||
- | =====Create the necessary jobs===== | ||
- | The jobs are needed so we can sync everything and start the log shipping/ | ||
- | |||
- | |||
- | <sxh bash> | ||
- | DECLARE @LS_Secondary__CopyJobId AS uniqueidentifier | ||
- | DECLARE @LS_Secondary__RestoreJobId AS uniqueidentifier | ||
- | DECLARE @LS_Secondary__SecondaryId AS uniqueidentifier | ||
- | DECLARE @LS_Add_RetCode As int | ||
- | |||
- | |||
- | EXEC @LS_Add_RetCode = master.dbo.sp_add_log_shipping_secondary_primary | ||
- | @primary_server = N' | ||
- | , | ||
- | , | ||
- | , | ||
- | , | ||
- | , | ||
- | , | ||
- | , | ||
- | , | ||
- | , | ||
- | , | ||
- | |||
- | IF (@@ERROR = 0 AND @LS_Add_RetCode = 0) | ||
- | BEGIN | ||
- | |||
- | DECLARE @LS_SecondaryCopyJobScheduleUID As uniqueidentifier | ||
- | DECLARE @LS_SecondaryCopyJobScheduleID AS int | ||
- | |||
- | |||
- | EXEC msdb.dbo.sp_attach_schedule | ||
- | @job_id = @LS_Secondary__CopyJobId | ||
- | , | ||
- | |||
- | DECLARE @LS_SecondaryRestoreJobScheduleUID As uniqueidentifier | ||
- | DECLARE @LS_SecondaryRestoreJobScheduleID AS int | ||
- | |||
- | |||
- | EXEC msdb.dbo.sp_attach_schedule | ||
- | @job_id = @LS_Secondary__RestoreJobId | ||
- | , | ||
- | |||
- | |||
- | END | ||
- | |||
- | |||
- | DECLARE @LS_Add_RetCode2 As int | ||
- | |||
- | |||
- | EXEC @LS_Add_RetCode2 = master.dbo.sp_add_log_shipping_secondary_database | ||
- | @secondary_database = N' | ||
- | , | ||
- | , | ||
- | , | ||
- | , | ||
- | , | ||
- | , | ||
- | , | ||
- | , | ||
- | , | ||
- | |||
- | |||
- | IF (@@error = 0 AND @LS_Add_RetCode = 0) | ||
- | BEGIN | ||
- | |||
- | EXEC msdb.dbo.sp_update_job | ||
- | @job_id = @LS_Secondary__CopyJobId | ||
- | ,@enabled = 1 | ||
- | |||
- | EXEC msdb.dbo.sp_update_job | ||
- | @job_id = @LS_Secondary__RestoreJobId | ||
- | ,@enabled = 1 | ||
- | |||
- | END | ||
- | |||
- | |||
- | </ | ||
- | Congrats you have brand new log shipping configuration | ||
- | |||
- | |||
- | ====Remove the configuration==== | ||
- | Again if you mistake the configuration for some reason, you can use the following procedure to remove it: | ||
- | |||
- | <sxh bash> | ||
- | sp_delete_log_shipping_secondary_database [ @secondary_database = ] ' | ||
- | </ | ||
- | |||
- | |||
- | P.S. This will remove also any created jobs. | ||
- | ======Misc====== | ||
- | |||
- | ====Change restore option==== | ||
- | If you made error of the restore type, you edit the restore job configuration as follows: | ||
- | |||
- | <sxh bash> | + | [[mssql_log_shipping_switchover|Switchover]] |
- | exec sp_change_log_shipping_secondary_database @secondary_database = ' | + | |
- | </ | + | |
+ | * Perform Tail-log Backup (On Primary) | ||
+ | * Restore with RECOVERY (On Standby) |