SQL Server 2005數(shù)據(jù)庫鏡像配置腳本示例

字號:


    這篇論壇文章(賽迪網(wǎng)技術(shù)社區(qū))主要介紹了SQL Server 2005數(shù)據(jù)庫鏡像的配置腳本,詳細(xì)內(nèi)容請大家參考下文:
    SQL Server 2005數(shù)據(jù)庫鏡像配置腳本:
    示例如下:
    --在MIR-A上,創(chuàng)建數(shù)據(jù)庫鏡像端點
    create endpoint DB_MirroringEP
    AS tcp (listener_port = 5022)
    for database_Mirroring (role = partner,encryption=supported);
    go
    --在MIR-B上,創(chuàng)建數(shù)據(jù)庫鏡像端點,用于伙伴通訊
    CREATE ENDPOINT Db_MirroringEP
    AS TCP (LISTENER_PORT = 5022)
    FOR DATABASE_MIRRORING (ROLE = PARTNER, ENCRYPTION = SUPPORTED);
    GO
    ALTER ENDPOINT Db_MirroringEP STATE = STARTED
    GO
    --在MIR-W上,創(chuàng)建數(shù)據(jù)庫鏡像端點,用于見證通訊
    CREATE ENDPOINT Db_MirroringEP
    AS TCP (LISTENER_PORT = 5022)
    FOR DATABASE_MIRRORING (ROLE = WITNESS, ENCRYPTION = SUPPORTED);
    GO
    ALTER ENDPOINT Db_MirroringEP STATE = STARTED
    GO
    --在MIR-A,MIR-B,MIR-W上,檢查端點配置
    SELECT * FROM sys.database_mirroring_endpoints
    GO
    --在MIR-A,MIR-B,MIR-W上,配置數(shù)據(jù)庫鏡像安全性,somodesql.com為自己的域名
    use master
    go
    grant connect on endpoint::"DB_MirroringEP" to "SOMODESQL\sqladmin"
    go
    --在MIR-A上,對AdventureWorks數(shù)據(jù)庫做完全備份
    BACKUP DATABASE AdventureWorks TO DISK = 'C:\AdventureWorks.bak'
    GO
    --在MIR-B上恢復(fù)AdventureWorks數(shù)據(jù)庫。
    --通過安全方法,將 C:\AdventureWorks.bak 復(fù)制到 MIR-B。
    --在 MIR-B 的鏡像服務(wù)器實例上還原數(shù)據(jù)庫:
    RESTORE DATABASE AdventureWorks
    FROM DISK = 'C:\AdventureWorks.bak'
    WITH NORECOVERY
    GO
    --啟動數(shù)據(jù)庫鏡像,注意順序,需要在首先在鏡像服務(wù)器上配置伙伴
    --在MIR-B上,指定伙伴端點,somodesql.com為自己的域名
    alter database AdventureWorks
    set partner = N'TCP://MIR-A.somodesql.com:5022'
    GO
    --在MIR-A上,指定伙伴端點
    alter database AdventureWorks
    set partner = N'TCP://MIR-B.somodesql.com:5022'
    GO
    --在MIR-A上,指定見證服務(wù)器端點
    ALTER DATABASE AdventureWorks
    SET WITNESS = N'TCP://MIR-W.somodesql.com:5022'
    GO
    --配置數(shù)據(jù)庫鏡像事務(wù)安全級別
    ALTER DATABASE AdventureWorks SET SAFETY FULL
    GO
    --=================查看數(shù)據(jù)庫鏡像的配置狀態(tài)=================
    -- 1.)通過Management studio 對象資源管理器,查看主體數(shù)據(jù)庫、鏡像數(shù)據(jù)庫狀態(tài)
    -- 2.)通過Management studio 對象資源管理器中的數(shù)據(jù)庫屬性查看狀態(tài)
    -- 3.)通過系統(tǒng)目錄視圖查看數(shù)據(jù)庫鏡像配置情況
    use master
    go
    SELECT * FROM sys.database_mirroring_endpoints
    SELECT * FROM sys.database_mirroring WHERE database_id =
    (SELECT database_id FROM sys.databases WHERE name = 'AdventureWorks')