Background:

It's fairly common for businesses to want to provide some high availability for their SQL Server databases, and one option is to have two SQL Server databases on separate machines with a SQL Server database mirrored. Microsoft provides mirroring out of the
box in SQL Server 2005 and SQL Server 2008, and is a much cheaper alternative than going down the clustering/failover route, but does provide some protection. In mirroring, there is always one Principal database which serves the requests, and a standby Mirror
that is always synchronizing. If the Principal database goes down, then the Mirror can be forced to become the Principal, and will then serve the requests. Once the original Principal is available again, it will become the new Mirror.

Restrictions on Backup and Restore During Mirroring

While a database mirroring session is active, the following restrictions apply:

  • Backup and restore of the mirror database are not allowed.

  • Backup of the principal database is allowed, but BACKUP LOG WITH NORECOVERY is not allowed.

  • Restoring the principal database is not allowed.

Script in Principal:

-- Step 1
USE master;
CREATE MASTER KEY ENCRYPTION BY PASSWORD ='Password01!';
CREATE CERTIFICATE HOST_pri_cert WITH SUBJECT ='HOST_pri certificate' ,
START_DATE = '01/11/2014', EXPIRY_DATE = '01/11/2015'; -- Step 2
alter ENDPOINT Endpoint_Mirroring
STATE = STARTED
AS TCP ( LISTENER_PORT=50221 , LISTENER_IP = ALL )
FOR DATABASE_MIRRORING
( AUTHENTICATION = CERTIFICATE HOST_pri_cert , ENCRYPTION = REQUIRED ALGORITHM AES , ROLE = ALL ) --SELECT * FROM sys.endpoints;
-- drop ENDPOINT Mirroring_Endpoint2
Go -- Step 3
BACKUP CERTIFICATE HOST_pri_cert TO FILE = 'D:\Hot backup\HOST_pri_cert.cer'; -- Step 4
use master
Create LOGIN HOST_min_login WITH PASSWORD ='Password01!';
CREATE USER HOST_min_user FOR LOGIN HOST_min_login;
--drop CERTIFICATE HOST_min_cert
CREATE CERTIFICATE HOST_min_cert AUTHORIZATION HOST_min_user FROM FILE ='D:\Hot backup\HOST_min_cert.cer';
GRANT CONNECT ON ENDPOINT::Endpoint_Mirroring TO [HOST_min_login]; Create LOGIN HOST_pro_login WITH PASSWORD ='Password01!';
CREATE USER HOST_pro_user FOR LOGIN HOST_pro_login;
-- drop CERTIFICATE HOST_pro_cert
CREATE CERTIFICATE HOST_pro_cert AUTHORIZATION HOST_pro_user FROM FILE ='D:\Hot backup\HOST_pro_cert.cer';
GRANT CONNECT ON ENDPOINT::Endpoint_Mirroring TO [HOST_pro_login]; -- select * from sys.database_principals
GO -- Step 5
USE master;
ALTER DATABASE TestBackup01
SET RECOVERY FULL;
Go -- Step 6
USE TestBackup01 --back up data
GO
BACKUP DATABASE [TestBackup01] TO DISK = N'D:\Hot backup\testbackup01.bak' WITH NOFORMAT, NOINIT, NAME = N'TestBackup01-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10
GO BACKUP LOG [TestBackup01] TO DISK = N'D:\Hot backup\TestBackup01.trn' WITH NOFORMAT, NOINIT, NAME = N'TestBackup01-Transaction Log Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10
GO

Script in Mirror:

-- Step 1
USE master;
CREATE MASTER KEY ENCRYPTION BY PASSWORD ='Password01!';
CREATE CERTIFICATE HOST_min_cert WITH SUBJECT ='HOST_mirror certificate' ,
START_DATE = '01/11/2014', EXPIRY_DATE = '01/11/2015'; -- Step 2
Alter ENDPOINT Endpoint_Mirroring
STATE = STARTED
AS TCP ( LISTENER_PORT=50221 , LISTENER_IP = ALL )
FOR DATABASE_MIRRORING ( AUTHENTICATION = CERTIFICATE HOST_min_cert , ENCRYPTION = REQUIRED ALGORITHM AES , ROLE = ALL )
-- drop endpoint Mirroring
-- SELECT * FROM sys.endpoints;
Go -- Step 3
BACKUP CERTIFICATE HOST_min_cert TO FILE = 'D:\Hot backup\HOST_min_cert.cer';
--SELECT * FROM sys.certificates;
Go -- Step 4
CREATE LOGIN HOST_pri_login WITH PASSWORD ='Password01!';
CREATE USER HOST_pri_user FOR LOGIN HOST_pri_login;
drop CERTIFICATE HOST_pri_cert
CREATE CERTIFICATE HOST_pri_cert AUTHORIZATION HOST_pri_user FROM FILE ='D:\Hot backup\HOST_pri_cert.cer';
GRANT CONNECT ON ENDPOINT::Endpoint_Mirroring TO [HOST_pri_login]; CREATE LOGIN HOST_pro_login WITH PASSWORD ='Password01!';
CREATE USER HOST_pro_user FOR LOGIN HOST_pro_login;
drop CERTIFICATE HOST_pro_cert
CREATE CERTIFICATE HOST_pro_cert AUTHORIZATION HOST_pro_user FROM FILE ='D:\Hot backup\HOST_pro_cert.cer';
GRANT CONNECT ON ENDPOINT::Endpoint_Mirroring TO [HOST_pro_login]; -- Step 5
create database TestBackup01USE master;
ALTER DATABASE TestBackup01SET RECOVERY FULL;
RESTORE DATABASE TestBackup01 FROM DISK = 'D:\Hot backup\backup_TestBackup01.bak' WITH FILE = 1, NORECOVERY, NOUNLOAD;
RESTORE LOG TestBackup01 FROM DISK = 'D:\Hot backup\backup_TestBackup01.trn' WITH FILE = 2, NORECOVERY, NOUNLOAD

Script in Witness:

-- Step 1
USE master;
CREATE MASTER KEY ENCRYPTION BY PASSWORD ='Password01!';
CREATE CERTIFICATE HOST_pro_cert WITH SUBJECT = 'HOST_Witness certificate' ,
START_DATE = '01/11/2014', EXPIRY_DATE = '01/11/2015'; -- Step 2
Create ENDPOINT Endpoint_Mirroring
STATE = STARTED
AS TCP ( LISTENER_PORT=50221 , LISTENER_IP = ALL )
FOR DATABASE_MIRRORING
( AUTHENTICATION = CERTIFICATE HOST_pro_cert , ENCRYPTION = REQUIRED ALGORITHM AES , ROLE = ALL )
select * from sys.endpoints
Go -- Step 3
BACKUP CERTIFICATE HOST_pro_cert TO FILE = 'D:\Hot backup\HOST_pro_cert.cer'; --Note: Full Name -- Step 4
CREATE LOGIN HOST_min_login WITH PASSWORD ='Password01!';
CREATE USER HOST_min_user FOR LOGIN HOST_min_login;
CREATE CERTIFICATE HOST_min_cert AUTHORIZATION HOST_min_user FROM FILE ='D:\Hot backup\HOST_min_cert.cer';
GRANT CONNECT ON ENDPOINT::Endpoint_Mirroring TO [HOST_min_login]; CREATE LOGIN HOST_pri_login WITH PASSWORD ='Password01!';
CREATE USER HOST_pri_user FOR LOGIN HOST_pri_login;
CREATE CERTIFICATE HOST_pri_cert AUTHORIZATION HOST_pri_user FROM FILE ='D:\Hot backup\HOST_pri_cert.cer';
GRANT CONNECT ON ENDPOINT::Endpoint_Mirroring TO [HOST_pri_login];
--select * from sys.database_principals
Go -- Step 5
Create database TestBackup01 USE master;
ALTER DATABASE TestBackup01
SET RECOVERY FULL;
RESTORE DATABASE TestBackup01 FROM DISK = 'D:\Hot backup\backup_TestBackup01.bak' WITH FILE = 1, NORECOVERY, NOUNLOAD;
RESTORE LOG TestBackup01 FROM DISK = 'D:\Hot backup\backup_TestBackup01.trn' WITH FILE = 2, NORECOVERY, NOUNLOAD
Go

Note:

1. copy the certificates over to the other server(Mirror, Witness and Principal).

2. After coping the certificates over I setup the logins.

3. Back up and restore db with log.

  • Perform a full backup of the database on the Principal server.
  • Perform a Transaction Log backup on the Principal server.
  • Copy the backup file to the Mirror.
  • Important: Do a restore of the full backup into a new step, but before doing the restore, go to Options, then ensure you check the No Recovery option! This is vital!
  • Perform another restore of the Transaction Log, also with the No Recovery option. (This is important, otherwise you'll get an error when starting the mirror - See Gotchas section for explanation).

SQL Mirroring[Hot back up with Double machine]的更多相关文章

  1. Lync 2013安装中遇到的关于SQL Mirroring的一次报错的解决

    Problem Description ================= Following the Lync Deployment Wizard to setup Database Mirrori ...

  2. java.sql.SQLException: Data truncation: Truncated incorrect DOUBLE value

    mysql 报这个异常:java.sql.SQLException: Data truncation: Truncated incorrect DOUBLE value update 表名 set c ...

  3. Paper慢慢读 - AB实验人群定向 Double Machine Learning

    Hetergeneous Treatment Effect旨在量化实验对不同人群的差异影响,进而通过人群定向/数值策略的方式进行差异化实验,或者对实验进行调整.Double Machine Learn ...

  4. T-SQL 语句创建Database的SQL mirroring关系

    1 证书部分:principle 和 secondary 端执行同样操作,更改相应name即可 USE master; --1.1 Create the database Master Key, if ...

  5. Sql的decimal、float、double类型的区别

    三者的区别介绍 float:浮点型,含字节数为4,32bit,数值范围为-3.4E38~3.4E38(7个有效位) double:双精度实型,含字节数为8,64bit数值范围-1.7E308~1.7E ...

  6. sql Mirroring

    http://www.codeproject.com/Articles/109236/Mirroring-a-SQL-Server-Database-is-not-as-hard-as http:// ...

  7. [SQL in Azure] Provisioning a SQL Server Virtual Machine on Azure

    http://azure.microsoft.com/en-us/documentation/articles/virtual-machines-provision-sql-server/ Provi ...

  8. [SDK2.2]SQL Azure (13) Azure的两种关系型数据库服务:SQL Azure与SQL Server VM的不同

    <Windows Azure Platform 系列文章目录> 如果熟悉Windows Azure平台的用户不难发现,对于SQL Server数据库来说,微软提供了两种服务,分别是: -W ...

  9. Azure的两种关系型数据库服务:SQL Azure与SQL Server VM的不同

    Azure的两种关系型数据库服务:SQL Azure与SQL Server VM的不同 <Windows Azure Platform 系列文章目录> 如果熟悉Windows Azure平 ...

随机推荐

  1. HDU 4360 As long as Binbin loves Sangsang spfa

    题意: 给定n个点m条边的无向图 每次必须沿着LOVE走,到终点时必须是完整的LOVE,且至少走出一个LOVE, 问这样情况下最短路是多少,在一样短情况下最多的LOVE个数是多少. 有自环. #inc ...

  2. 每天进步一点点——再次了解Linux进程ID

    转载请注明出处:http://blog.csdn.net/cywosp/article/details/38968011 1. 概述 众所周知,进程(process)是一个可运行程序的实例,可是在Li ...

  3. TimesTen更改CacheGroup管理用户ORACLE结束和TT结束password【TimesTen操作和维修基地】

    password管理一直操作的一部分的安全管理和维护.CacheGroup管理用户password虽然并不复杂变化.然而,这是用于生产,改不好比较easy导致失败.简介点击这里CacheGroup管理 ...

  4. Docker部署JavaWeb项目实战(转)

    摘要:本文主要讲了如何在Ubuntu14.04 64位系统下来创建一个运行Java web应用程序的Docker容器. 一.下载镜像.启动容器 1.下载镜像 先查看镜像 docker images 记 ...

  5. 【原创】用Python爬取LeetCode的AC代码到Github

    在leetCode写了105道题高调膜科,考虑搬迁到自己的GitHub上,做成一个解题题库,面试的时候也可以秀一个 但是!但是! leetCode在线IDE的功能不要太舒服,我直接线上A了不少题,本地 ...

  6. HDU 1874 畅通公程续 (最短路 水)

    Problem Description 某省自从实行了非常多年的畅通project计划后,最终修建了非常多路.只是路多了也不好,每次要从一个城镇到还有一个城镇时,都有很多种道路方案能够选择,而某些方案 ...

  7. Oracle 闪回表实验

    工:闪回表实验 1.结构测试表flb_test,数据不小于10000行: TEST_USER1@PROD>create table flb_test(id number,dd date); Ta ...

  8. Android 角色时间戳

    我是在用MediaRecorder进行录像时发生视频和音频不同步的问题,请教了一些人后感觉应该是没有时间戳,之前一直觉得时间戳就是给用户看的一个数据,查了一下发现不是的,以下是转载的.希望对大家实用: ...

  9. pdf转换为word小工具,挺好

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZGFwZW5nMDExMg==/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...

  10. UVA580-Critical Mass

    题目链接 题意:一个栈中仅仅能放入U和L,问存在连续3个以上U(危急组合)的个数为几个 思路:用总组合数-安全组合=危急组合.d[i]表示第i个位置以L结束的序列,所以就有d[i] = d[i - 1 ...