About Log Shipping (SQL Server)
SQL Server Log shipping allows you to automatically send transaction log backups from a primary database on aprimary server instance to one or moresecondary databases on separate secondary server instances. The transaction log backups are applied to each of the secondary databases individually. An optional third server instance, known as the monitor server, records the history and status of backup and restore operations and, optionally, raises alerts if these operations fail to occur as scheduled.
Logshipping 允许你自动从一个主服务器实例的主库发送事务日志备份到一个或者多个独立的备库服务器实例备库上。事务日志会分别被每个备库进行应用。还有一个可选的服务器实例,叫做监控服务器,它记录备份与还原操作的历史记录,并且有需要的话,可以在以上操作未按计划执行时发出警告。
-
Provides a disaster-recovery solution for a single primary database and one or more secondary databases, each on a separate instance of SQL Server.
-
Supports limited read-only access to secondary databases (during the interval between restore jobs).
-
Allows a user-specified delay between when the primary server backs up the log of the primary database and when the secondary servers must restore (apply) the log backup. A longer delay can be useful, for example, if data is accidentally changed on the primary database. If the accidental change is noticed quickly, a delay can let you retrieve still unchanged data from a secondary database before the change is reflected there.
益处:
1. 为单实例数据库与一个或者多个备库提供容灾解决方案,他们分别位于独立SQL服务器上。
2. 提供针对备库有限的只读服务(在还原任务间隔之间)
3. 允许用户指定的在主库服务器备份主库日志的时间与备库服务器必须还原(应用)备份日志的时间之间的延迟。较长的延迟可能是有用的,例如如果数据在主库上意外被修改了,如果这个修改很快被发现,这个时间延迟可以让你仍然可以在备库反应这一数据改变之前,得到未被修改的数据。(难道没有类似Oracle 的flashback机制么?)
术语与定义:
主服务器:
生产SQL Server 服务器
主库:
主服务器上你想将其备份到其他服务器上的数据库。所有log shipping配置项的管理都是通过SQL Server Management Studio(SQL2005 开始出现的,前身是企业管理器)在主库上配置的。
备用服务器:
用来保存主库热备的地方(SQL Server服务器)
备库:
是主库的热备份,备库可能出于recovering状态与standby状态,同时提供有限的只读服务。
监控服务器:
一个可选的服务器实例用来跟踪log shipping的全部细节,包括:
1.主库的事务日志最后一次备份是何时
2.备用服务器最后一次拷贝与还原文件是何时
3.关于任何备份失败的信息
注意:一旦监控服务器配置完毕,除非移除log shipping,否则不能进行更改。
备份任务:
一个sqlserver 用来执行备份操作的代理任务,记录本地服务器与监控服务器的历史信息,并且删除旧的备份文件与历史信息。当log shipping被启用时,一个名为“log shipping backup”任务类型在主服务器上被创建。
拷贝任务:
一个sqlserver 的代理任务,用来从主服务器将备份文件拷贝到备用服务器指定目的地。当log shipping被启用时,一个名为“log shipping copy”任务类型在备用服务器上的logshipping配置中被创建。
还原任务:
一个sqlserver 的代理任务,用来将备份文件还原到备库。它在本地记录本地服务器与监控服务器的历史信息。并且伤处就的文件与旧历史信息。当log shipping启用时,一个名为“log shipping restore”的任务类型在备用服务器实例上被创建。
警告任务:
一个sqlserver的代理任务,用来在主备库的备份与恢复操作没有成功完成,且达到指定阀值时,发出警告。当log shipping启动时,一个名为“log shipping alert”的任务类型在监控服务器实例上被创建。
提示: 针对每个警告,你需要指定一个编号,并且通过配置确保警告时可以触发一个操作行为。
Log Shipping Overview
Log shipping consists of three operations:
-
Back up the transaction log at the primary server instance.
-
Copy the transaction log file to the secondary server instance.
-
Restore the log backup on the secondary server instance.
The log can be shipped to multiple secondary server instances. In such cases, operations 2 and 3 are duplicated for each secondary server instance.
A log shipping configuration does not automatically fail over from the primary server to the secondary server. If the primary database becomes unavailable, any of the secondary databases can be brought online manually.
You can use a secondary database for reporting purposes.
In addition, you can configure alerts for your log shipping configuration.
log shipping 概述
包含三个操作:
1. 在主服务器实例备份事务日志
2. 拷贝事务日志文件至备用服务器
3. 在备库服务器还原日志备份
日志可以被传输到多个备用服务器,在这类情况下,第2,3步要在每个备用服务器上重复。log shipping的配置不会自动在故障时从主服务器切换到备用服务器。如果主库不可用了,任何一个备库可以被手动启动提供服务。
你可以将备库用于报表用途。
除此之外,你可以为log shipping配置警告信息。
A Typical Log Shipping Configuration
The following figure shows a log shipping configuration with the primary server instance, three secondary server instances, and a monitor server instance. The figure illustrates the steps performed by backup, copy, and restorejobs, as follows:
-
The primary server instance runs the backup job to back up the transaction log on the primary database. This server instance then places the log backup into a primary log-backup file, which it sends to the backup folder. In this figure, the backup folder is on a shared directory—the backup share.
-
Each of the three secondary server instances runs its own copy job to copy the primary log-backup file to its own local destination folder.
-
Each secondary server instance runs its own restore job to restore the log backup from the local destination folder onto the local secondary database.
The primary and secondary server instances send their own history and status to the monitor server instance.
一个典型的log shipping配置
一下图例战术了一个log shipping配置,包括主服务器实例与3个备用服务器实例,还有一个监控服务器实例。图例说明了进行备份,拷贝,还原任务的步骤:
1. 主服务器实例运行备份任务以备份主库的事务日志。然后这个服务器实例将日志备份放到一个“主日志备份文件”,并且被发送到备份文件夹,在这个图例中,备份文件夹在共享的目录中。
2. 3个备用服务器中每个服务器实例都会运行自己的拷贝任务以拷贝“主日志备份文件”至自己的本地目标文件夹。
3. 每个备用服务器实例运行自己的还原任务,以将日志备份从本地目标文件夹中还原到本地备库。
主备库服务器实例与他们自己的历史信息与状态发送给监控服务器。
