SQL Mirroring[Hot back up with Double machine]
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]的更多相关文章
- Lync 2013安装中遇到的关于SQL Mirroring的一次报错的解决
Problem Description ================= Following the Lync Deployment Wizard to setup Database Mirrori ...
- java.sql.SQLException: Data truncation: Truncated incorrect DOUBLE value
mysql 报这个异常:java.sql.SQLException: Data truncation: Truncated incorrect DOUBLE value update 表名 set c ...
- Paper慢慢读 - AB实验人群定向 Double Machine Learning
Hetergeneous Treatment Effect旨在量化实验对不同人群的差异影响,进而通过人群定向/数值策略的方式进行差异化实验,或者对实验进行调整.Double Machine Learn ...
- T-SQL 语句创建Database的SQL mirroring关系
1 证书部分:principle 和 secondary 端执行同样操作,更改相应name即可 USE master; --1.1 Create the database Master Key, if ...
- Sql的decimal、float、double类型的区别
三者的区别介绍 float:浮点型,含字节数为4,32bit,数值范围为-3.4E38~3.4E38(7个有效位) double:双精度实型,含字节数为8,64bit数值范围-1.7E308~1.7E ...
- sql Mirroring
http://www.codeproject.com/Articles/109236/Mirroring-a-SQL-Server-Database-is-not-as-hard-as http:// ...
- [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 ...
- [SDK2.2]SQL Azure (13) Azure的两种关系型数据库服务:SQL Azure与SQL Server VM的不同
<Windows Azure Platform 系列文章目录> 如果熟悉Windows Azure平台的用户不难发现,对于SQL Server数据库来说,微软提供了两种服务,分别是: -W ...
- Azure的两种关系型数据库服务:SQL Azure与SQL Server VM的不同
Azure的两种关系型数据库服务:SQL Azure与SQL Server VM的不同 <Windows Azure Platform 系列文章目录> 如果熟悉Windows Azure平 ...
随机推荐
- 数据验证validator 与 DWZ
在进行系统经常使用的数据验证.数据验证可以编写自己的,它也可以用来作为现在.现在,记录这两个库的使用, validator <!DOCTYPE HTML PUBLIC "-//W3C/ ...
- Mvc后台接收 参数
@Html.TextAreaFor(m => m.Emps, new { @class = "easyui-validatebox", @style = "heig ...
- python 调用图灵机器人api实现简单的人机交互
接入流程例如以下,须要先注冊开发人员帐号,之后会得到一个32位的key,保存下来,用于以后发送数据.http://www.tuling123.com/ 请求方式 演示样例: # -*- coding: ...
- 【Swift】学习笔记(一)——熟知 基础数据类型,编码风格,元组,主张
自从苹果宣布swift之后,我一直想了解,他一直没有能够把它的正式学习,从今天开始,我会用我的博客来驱动swift得知,据我们了解还快. 1.定义变量和常量 var 定义变量,let定义常量. 比如 ...
- LeetCode: Multiply Strings. Java
Given two numbers represented as strings, return multiplication of the numbers as a string. Note: Th ...
- #define XXX do{ XXX } while(0) 为什么使用
#define XXX do{ XXX } while(0) 为什么使用 时常会遇到一个非常"奇怪的宏定义", rt.(欧西巴...思考不够深刻啊, 皮鞭, 啪啪啪) 近期又遇到这 ...
- li排序
html <ul id="ul1"> <li>9</li> <li>2</li> <li>7</li& ...
- Directx11学习笔记【十四】 使用最新的Effect框架和SDK
由于之前一直在看directx11龙书学习,因此sdk一直用的Microsoft DirectX SDK (June 2010) 版本,最近在stackoverflow上问dx11相关问题时,一直被大 ...
- 每天努力一点之SQL
今天工作当中遇到一个问题:统计信息并导出EXcel 报表. 刚开始只做了统计信息: 如下图 请看最后一列的数据. 我当时想都从数据库里取出来,但是由于我能力有限没有做出来.先贴下后来写的SQL 语句. ...
- HDU 4391 Paint The Wall 段树(水
意甲冠军: 特定n多头排列.m操作 以下是各点的颜色 以下m一种操纵: 1 l r col 染色 2 l r col 问间隔col色点 == 通的操作+区间内最大最小颜色数的优化,感觉非常不科学... ...