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平 ...
随机推荐
- Python使用subprocess的Popen要调用系统命令
当我们须要调用系统的命令的时候,最先考虑的os模块.用os.system()和os.popen()来进行操作.可是这两个命令过于简单.不能完毕一些复杂的操作,如给执行的命令提供输入或者读取命令的输出, ...
- ALSA安装编程指南
ALSA全指南 一.什么是ALSA ALSA是Advanced Linux Sound Architecture,高级Linux声音架构的简称,它在Linux操作系统上提供了音频和MIDI(Mu ...
- Xcode 5.1.1 与 Xcode 6.0.1 共存
Xcode 5.1.1 (下面简称Xcode5)和Xcode 6.0.1(下面简称Xcode6)都是正式版本号.其应用程序文件名称都是"Xcode".假设通过AppStore升级或 ...
- uitableView 选择跳过后, 跳回 颜色变化 问题
今天遇到这个问题 谁也因此没有满足这方面的需求 今天会见 网上办理登机手续 未找到 好 我只能说自己的问题 但 幸好,kai哥 就攻克了 ! 就是在- (void)tableView:(UITabl ...
- gerrit git使用
有关git的參考资料 pro git中文版, 最好的git书籍 http://git-scm.com/book/zh 图解git http://marklodato.github.com/visual ...
- Oracle 六闪回技术,flashback
Flashback 技术基于Undo segment基于内容的, 因此,限制UNDO_RETENTON参数. 要使用flashback 特征,您必须启用自己主动撤销管理表空间. 在Oracle 11g ...
- 【.NET进程通信】初探.NET中进程间通信的简单的实现
转载请注明出处:http://blog.csdn.net/xiaoy_h/article/details/26090277 废话不多说,IPC就是进程间通信. 进程间通信能够採用的方法非常多,比方创建 ...
- 【LeetCode】【Python解读】Container with most water
这个问题是芭芭拉在采访中遇到的,不幸的是,的复杂性O(n2)该,太失望了,难怪没有通过面试. Given n non-negative integers a1, a2, ..., an, where ...
- toString()和String.valueof()比较
toString()和String.valueof()比较 做项目时常常会用到类型转换,比较常用的是toString(),但其实还是用String.valueof()比较好.看源码后他们的区别就更加 ...
- XCODE4.6创建我的第一次ios规划:hello
对于非常多刚開始学习的人来说,肯定希望自己尝试不用傻瓜的"Single View Application"模板创建一个含有View的窗体.而是希望能从零開始,先建一个空的框架.然后 ...