Log shipping is a high-availability configuration that perhaps most of us are familiar with. It’s one of the oldest techniques wherein we ship transaction logs from a Primary database to a Secondary database. Log Shipping is still a vital feature used in case of applications that use warm standby for Disaster Recovery. We can see many articles which discuss the process of configuring Log shipping using T-SQL or SSMS.
日志传送是我们大多数人都熟悉的高可用性配置。 这是最古老的技术之一,其中我们将事务日志从主数据库发送到辅助数据库。 对于使用热备份进行灾难恢复的应用程序,日志传送仍然是一项至关重要的功能。 我们可以看到许多文章,这些文章讨论了使用T-SQL或SSMS配置日志传送的过程。
On a high level, Log Shipping consists of preparing the secondary database (NORECOVERY or STANDBY) using a backup of the primary instance database and then applying the transaction logs from the primary database onto the secondary database using SQL Server agent Jobs and a shared file location. In other words, it’s an automated process of restoring transaction log backups from the primary database server on to the secondary database/database server. This way, the database is available for failover.
在较高的级别上,日志传送包括使用主实例数据库的备份准备辅助数据库(NORECOVERY或STANDBY),然后使用SQL Server代理作业和共享文件位置将事务日志从主数据库应用到辅助数据库上。 换句话说,这是将事务日志备份从主数据库服务器还原到辅助数据库/数据库服务器的自动化过程。 这样,数据库可用于故障转移。
We’ve seen multiple models of implementation of log shipping: log shipping on the same server, on to a different server, across domains or workgroups, or to different versions of SQL Server. SQL Server, now being available for Linux, makes us think, “Can we set up log shipping across platforms?”
我们已经看到了日志传送的多种实现模式:日志传送在同一服务器上,跨域或工作组,到不同服务器或不同版本SQL Server。 现在可用于LinuxSQL Server使我们想到:“我们可以跨平台设置日志传送吗?”
As it turns out, yes, we can. This article discusses the setup. We’ll use a network file share for the demonstration. Let’s jump right in!
事实证明,是的,我们可以。 本文讨论了安装程序。 我们将使用网络文件共享进行演示。 让我们跳进去吧!
As shown in the above figure, log shipping is comprised of the following steps:
Check the databases recovery model
检查数据库恢复模型
Use the below SQL query to check the recovery model of the database.
使用下面SQL查询来检查数据库的恢复模型。
SELECT name AS [Database Name], recovery_model_desc AS [Recovery Model] FROM sys.databases
Configure a File Share using the SAMBA protocol
使用SAMBA协议配置文件共享
We’re using CentOS for the procedure. The procedure may vary based on the Linux flavor/distribution you use.
我们使用的是CentOS。 该过程可能会因您使用的Linux版本/发行版而异。
#yum install samba samba-client samba-common
#cp /etc/samba/smb.conf /etc/samba/smb.conf.bak
Use any editor to edit the content of /etc/samba/smb.conf. I used VI. VIM or Nano should work, too. The entire content of the file should look like the text below.
使用任何编辑器来编辑/etc/samba/smb.conf的内容。 我用VI。 VIM或Nano也应该起作用。 文件的全部内容应类似于以下文本。
[global]
workgroup = HQNT
server string = Samba Server %v
netbios name = centos
security = user
map to guest = bad user
dns proxy = no
#============================ Share Definitions ==============================
[SQLShare]
Comment =Sql Backup
path = /var/opt/SQLBAckup/
browsable =yes
writable = yes
guest ok = yes
public = yes
The content of the Samba configuration is shown below
Samba配置的内容如下所示
#mkdir –p /var/opt/SQLBackup
#chown mssql /var/opt/sqlbackup
# chgrp mssql /var/opt/sqlbackup
#chmod –R 777 /var/opt/SQLBackup
#systemctl restart smb
#firewall-cmd --permanent --zone=public --add-service=samba
# firewall-cmd --reload
#chcon -R -t samba_share_t /var/opt/SQLBackup/
Now that we have Samba set up, let’s move on to the next step.
现在我们已经设置了Samba,让我们继续下一步。
Install SQL Server Agent
安装SQL Server代理
The SQL Server agent jobs are the backbone of the Log Shipping architecture. The Backup Job, Copy Job, Restore Job, Alert job… all run on the Primary or the Secondary databases instances. To install the SQL Server Agent, the following commands are executed. After the installation is complete, don’t forget to restart the SQL Service.
SQL Server 代理作业是日志传送体系结构的基础。 备份作业,复制作业,还原作业,警报作业……都在主数据库或辅助数据库实例上运行。 要安装SQL Server代理,请执行以下命令。 安装完成后,请不要忘记重新启动SQL Service。
# yum install mssql-server-agent
#systemctl restart mssql-server
Setup Log Shipping
设置日志传送
Log shipping can be implemented using the SSMS GUI or T-SQL. I feel more comfortable using T-SQL. The sqlcmd command gives us the flexibility to execute the SQL by connecting to various versions SQL Shell with reference to the current scope of execution.
可以使用SSMS GUI或T-SQL来实现日志传送。 使用T-SQL使我感到更舒服。 sqlcmd命令通过参考当前执行范围连接到各种版本SQL Shell,使我们能够灵活地执行SQL。
The first task is to prepare the secondary database instance to get it up and running, by initializing the secondary database. We do this by restoring a full backup of the primary database on the secondary server with no recovery option. The transaction log backup is initiated on the primary and then copied across to the secondary database. This process applies the log on the secondary instance(s) of the database.
第一个任务是通过初始化辅助数据库来准备辅助数据库实例以使其启动并运行。 为此,我们在没有恢复选项的情况下在辅助服务器上还原了主数据库的完整备份。 事务日志备份在主数据库上启动,然后复制到辅助数据库上。 此过程将日志应用于数据库的辅助实例。
In this demonstration, HQ6021 is the Primary Server (running on Windows) and 10.2.6.10 is a Secondary Instance (running on Linux).
在此演示中,HQ6021是主服务器(在Windows上运行),而10.2.6.10是辅助实例(在Linux上运行)。
Copy the below SQL and open a SQLCMD session on SSMS to execute the commands. This creates a database called SQLShackLogShipping on the Secondary instance.
复制以下SQL并在SSMS上打开SQLCMD会话以执行命令。 这将在辅助实例上创建一个名为SQLShackLogShipping的数据库。
The first step in configuring log shipping is to initialize the secondary database, and restore the backup of the primary database on to the secondary instance.
配置日志传送的第一步是初始化辅助数据库,并将主数据库的备份还原到辅助实例上。
On the primary server,
在主服务器上,
On the secondary server,
在辅助服务器上,
The standard Log Shipping Status report can be generated by right clicking on the Server Name in the SQL Server Management Studio Reports Standard Reports Transaction Log Shipping Status. This report should give us details which should tell us whether our setup was successful.
可以通过在SQL Server Management Studio报表标准报表事务日志传输状态中的服务器名称上单击鼠标右键来生成标准的日志传输状态报告 。 此报告应向我们提供详细信息,这些详细信息应告诉我们设置是否成功。
As we saw in this article, the high availability feature, Log Shipping, can now be configured across platforms. This article provides step by step details of the configuration to implement Log Shipping from the primary SQL Server running on Windows to the secondary SQL Server running on CentOS. The steps are not very different from configuring Log Shipping across Windows instances, except that the interface (and so some of the commands) varies. You may get a few errors, but all the errors are going to be self-explanatory. If you can fix the Log Shipping setup on Windows, you should be able to troubleshoot configuration issues on Linux as well, as the steps should be straightforward. It is also evident that SQL Administrators have to quickly adapt to the changing needs of technology.
正如我们在本文中看到的,现在可以跨平台配置高可用性功能,即日志传送。 本文提供了配置的逐步详细信息,以实现从Windows上运行的主SQL Server到CentOS上运行的辅助SQL Server的日志传送。 这些步骤与跨Windows实例配置日志传送没有太大区别,只是接口(以及某些命令)有所不同。 您可能会遇到一些错误,但是所有错误都是不言而喻的。 如果您可以在Windows上修复“日志传送”设置,那么您也应该能够在Linux上解决配置问题,因为这些步骤应该很简单。 同样显而易见的是,SQL管理员必须快速适应不断变化的技术需求。
翻译自: https://www.sqlshack.com/set-sql-server-log-shipping-linux/