什么是SQL Server日志传送?

什么是SQL Server日志传送? (What is SQL Server log shipping?)

SQL Server日志传送是一种涉及两个或多个SQL Server实例,并将事务日志文件从一个SQL Server实例复制到另一个实例的技术。 跨SQL Server自动化传输事务日志文件和还原的过程。 作为处理结果,在两个不同的位置有两个数据副本

A log shipping session involves the following steps:

日志传送会话包括以下步骤:

  • Backing up the transaction log file on the primary SQL Server instance

    SQL Server实例上备份事务日志文件
  • Copying the transaction log backup file across the network to one or more secondary SQL Server instances

    跨网络将事务日志备份文件复制到一个或多个辅助 SQL Server实例
  • Restoring the transaction log backup file on the secondary SQL Server instances

    辅助 SQL Server实例上还原事务日志备份文件

实施实例 (Implementation examples)

One of the common log shipping scenarios is the environment with two servers (SQLServer-1 – primary and SQLServer-2 – secondary), two SQL Server instances (SQLInstance-1 and SQLInstance-2), and one SQL Server database named SQLDB-1 with log shipping running on it

常见的日志传送方案之一是具有两个服务器(SQLServer-1 – 服务器和SQLServer-2 – 辅助服务器),两个SQL Server实例(SQLInstance-1和SQLInstance-2)以及一个名为SQLDB-1SQL Server数据库的环境。在上面运行日志传送

什么是SQL Server日志传送?

Another common configuration is the environment with three (or more) servers (SQLServer-1 – primary, SQLServer-2 – secondary, and SQLServer-3 – secondary), three SQL Server instances (SQLInstance-1, SQLInstance-2, and SQLInstance-3), and one SQL Server database named SQLDB-1 with log shipping running on it

另一个常见的配置是具有三个(或更多)服务器(SQLServer-1 – 服务器,SQLServer-2 – 辅助服务器和SQLServer-3 – 辅助服务器),三个SQL Server实例(SQLInstance-1,SQLInstance-2和SQLInstance- 3),以及一个名为SQLDB-1SQL Server数据库,并在其上运行日志传送

什么是SQL Server日志传送?

操作模式 (Operating modes)

There are two available modes and they are related to the state in which the secondary, log shipped, SQL Server database will be:

有两种可用的模式,它们与SQL Server辅助日志发送数据库的状态有关:

  • Standby mode – the database is available for querying and users can access it, but in read-only mode
    • The database is not available only while the restore process is running
      • Users can be forced to disconnect when the restore job commence
      • The restore job can be delayed until all users disconnect themselves

    备用模式–数据库可供查询,用户可以以只读模式访问它
    • 该数据库仅在还原过程运行时不可用
      • 还原作业开始时,用户可能被迫断开连接
      • 还原作业可以延迟,直到所有用户断开连接
  • Restore mode – the database is not accessible

    还原模式–无法访问数据库

使用SQL Server日志传送的优缺点 (Advantages and disadvantages of using SQL Server log shipping)

SQL Server log shipping is primarily used as a disaster recovery solution. Using SQL Server log shipping has multiple benefits: it’s reliable and tested in details, it’s relatively easy to set up and maintain, there is a possibility for failover between SQL Servers, data can be copied on more than one location etc.

SQL Server日志传送主要用作灾难恢复解决方案。 使用SQL Server日志传送有多个好处:它可靠且经过详细测试,相对容易设置和维护,在SQL Server之间可能进行故障转移,可以将数据复制到多个位置等。

Log shipping can be combined with other disaster recovery options such as AlwaysOn Availability Groups, database mirroring, and database replication. Also, SQL Server log shipping has low cost in human and server resources

日志传送可以与其他灾难恢复选项(例如AlwaysOn可用性组,数据库镜像和数据库复制)结合使用。 另外,SQL Server日志传送在人力和服务器资源上的成本较低

The main disadvantages in the SQL Server log shipping technique are: need to manage all the databases separately, there isn’t possibility for an automatic failover, and secondary database isn’t fully readable while the restore process is running

SQL Server日志传送技术的主要缺点是:需要单独管理所有数据库,不可能进行自动故障转移,并且在还原过程运行时不能完全读取辅助数据库

设置数据库日志传送环境 (Setting up the database log shipping environment )

SQL Server log shipping is based on execution of predefined SQL Server jobs. The SQL Server log shipping feature is available in all SQL Server editions except the Express edition. All the databases intended to be used for log shipping must be in the Full or Bulk logged recovery model

SQL Server日志传送基于预定义SQL Server作业的执行。 除Express版本外,所有SQL Server版本均提供SQL Server日志传送功能。 所有打算用于日志传送的数据库必须处于完整或批量日志记录恢复模型中

Another important prerequisite is running SQL Server Agent on both servers. Security policies must be defined in order for SQL Server Agent to have permission to read and write in the backup folder. Note that SQL Server agent on the secondary server must be able to read from the primary server’s backup folder

另一个重要的前提条件是在两台服务器上都运行SQL Server代理。 必须定义安全策略,SQL Server代理才能在备份文件夹中进行读写操作。 请注意,辅助服务器上SQL Server代理必须能够从主服务器的备份文件夹中读取

The database backups can be compressed, but that requires additional CPU time. Most common configurations use network locations for storing the backups

可以压缩数据库备份,但是这需要额外的CPU时间。 最常见的配置使用网络位置来存储备份

The database log shipping setup needs to be initiated from the principal server using the SQL Server Management Studio wizard. The first step defines transaction log backup settings:

需要使用SQL Server Management Studio向导从主体服务器启动数据库日志传送设置。 第一步定义事务日志备份设置:

  • A network path to the backup

    备份的网络路径
  • How long backup files should be kept before deleting

    删除前备份文件应保留多长时间
  • An alert if no backup is taken

    没有备份时发出警报
  • The backup job itself
    • Schedule of the job
      • Schedule type
      • Frequency
      • Duration

    备份作业本身
    • 工作时间表
      • 时间表类型
      • 频率
      • 持续时间

什么是SQL Server日志传送?

The next step defines secondary databases which involve choosing the secondary SQL Server instance and secondary database. The full database backup, from the primary database, must be restored on the secondary server before log shipping commences

下一步定义辅助数据库,其中涉及选择辅助SQL Server实例和辅助数据库。 在开始日志传送之前,必须在辅助服务器上还原来自主数据库的完整数据库备份。

什么是SQL Server日志传送?

After initializing the secondary database you must define the copy folder where the transaction log backups from the primary server will be stored

初始化辅助数据库后,必须定义副本文件夹,该文件夹将存储来自主服务器的事务日志备份

The final step involves choosing from two available modes: The No recovery – Restore mode and Standby mode. You can also delay the restoring process and set up an alert if no restore occurs within the specified time

最后一步涉及从两个可用模式中进行选择:无恢复-还原模式和待机模式。 如果在指定时间内没有还原,您还可以延迟还原过程并设置警报。

什么是SQL Server日志传送?

Once the log shipping is ready for use, it will run in the background, and if the problem occurs the alert will signalize the problem

一旦准备好使用日志传送,它将在后台运行,并且如果发生问题,警报将发出问题信号。

什么是SQL Server日志传送?

翻译自: https://www.sqlshack.com/sql-server-log-shipping/