sqlserver2005 master與msdb數(shù)據庫備份恢復過程
由于系統(tǒng)數(shù)據庫對Sql Server來說尤其重要,為了確保SQL SERVER系統(tǒng)的正常運行,除了日常備份用戶的數(shù)據庫之外,我們還需要備份系統(tǒng)數(shù)據庫,如對Master,Model,Msdb(TempDB不需備份)進行完整備份
1、還原Master數(shù)據庫
如果系統(tǒng)配置丟失或Master出現(xiàn)問題,可以進入單用戶模式進行還原;如果出現(xiàn)下列情況,必須重新生成損壞的 master 數(shù)據庫:
A. master 數(shù)據庫的當前備份不可用。
B. 存在 master 數(shù)據庫備份,但由于 Microsoft SQL Server 實例無法啟動,因此無法還原該備份。
1、重新生成 master 數(shù)據庫:
注意:
在 SQL Server 2005 中已廢止 Rebuildm.exe 程序。若要重新生成 master 數(shù)據庫,請使用 setup.exe。
1、 Start /wait setup.exe /qn INSTANCENAME=<InstanceName> REINSTALL=SQL_Engine REBUILDDATABASE=1 SAPWD=<NewStrongPassword>
例:start /wait e:“setup.exe /qn INSTANCENAME=mssqlserver REINSTALL=SQL_Engine REBUILDDATABASE=1 SAPWD=abc123@!@
注:INSTANCENAME:指定實例名,默認實例則用mssqlserver表示
REINSTALL:指定引擎
SAPWD:強密碼
Setup.exe:指定光盤1中的根目錄下的文件
/qn 開關用于取消所有安裝程序對話框和錯誤消息。如果指定 /qn 開關,則所有安裝程序消息(包括錯誤消息)都將寫入安裝程序日志文件。有關日志文件的詳細信息,請參閱如何查看 SQL Server 2005 安裝日志文件。
指定 /qb 開關將顯示基本的安裝程序對話框。還會顯示錯誤消息。
2、 還原Master備份(在恢復master的備份時要注意:必須在單用戶(single user)模式下進行 ) a.進入單用戶模式的方法:
'1.在命令行模式下輸入sqlservr -c -f -m或者輸入sqlservr -m'
'其中:-c 可以縮短啟動時間,SQL Server 不作為Windows NT的服務啟動'
' -f 用最小配置啟動SQL Server'
'-m 單用戶模式啟動SQL Server'
2.系統(tǒng)默認沒有設置PATH,先進入CMD,進入“C:“Program Files“Microsoft SQL Server“MSSQL.1“MSSQL“Binn”,執(zhí)行SQLSERVR.EXE –M
打開SSMS工具,先斷開連接,再新建查詢,執(zhí)行以下命名還原
USE master
GO
RESTORE DATABASE master
FROM disk=‘c:“master.bak‘
GO
開始實驗了~~~
MASTER重新生成
為了模擬MASTER數(shù)據庫壞了,我們就刪除MASTER數(shù)據庫(要停止SQL SERVER服務才能刪除)在我的電腦,C:“ PROGRAM FILES“MICROSOFT SQL SERVER“MSSQL.1“MSSQL“DATE 中刪除MASTER.MDF
重新生成MASTER
1.首先在CMD中輸入
start /wait setup.exe /qn INSTANCENAME=<InstanceName> REINSTALL=SQL_Engine REBUILDDATABASE=1 SAPWD=<NewStrongPassword>
其中的 SETUP.EXE為啟動光盤的路徑,我這里的是 E:“SETUP.EXE /QN
我這里的為默認實例所以其中的<INSTANCENAME>用 MSSQLSERVER代替
最后的<NewStrongPassword>為密碼我設密碼為abc123@!@,所以就用abc123@!@代替<NewStrongPassword>
若沒有返回錯誤,我們就可以到我的電腦中C:“ PROGRAM FILES“MICROSOFT SQL SERVER“MSSQL.1“DATE上面又有MASTER.MDF了
接下來進入目錄
單用戶模式
啟動SSMS工具,新建查詢
輸入命令
啟動服務(MSSQL SERVER)
打開SSMS
連接到數(shù)據庫后就可以發(fā)現(xiàn)數(shù)據庫中的數(shù)據又回來了
以下是我在命令行下搞的命令,我用記事本的方式全部復制下來了,為了不傳附件,我就直接粘貼到下面了
Microsoft Windows [版本 5.2.3790]
(C) 版權所有 1985-2003 Microsoft Corp.
C:“Documents and Settings“Administrator>start /wait e:“setup.exe /qn INSTANCENAME=mssqlserver REINSTALL=SQL_Engine REBUILDDATABASE=1 SAPWD=abc123@!@
C:“Documents and Settings“Administrator>cd C:“Program Files“Microsoft SQL Server“MSSQL.1“MSSQL“Binn
C:“Program Files“Microsoft SQL Server“MSSQL.1“MSSQL“Binn>sqlservr.exe -m
2008-04-18 15:47:46.56 Server Authentication mode is MIXED.
2008-04-18 15:47:46.59 Server Microsoft SQL Server 2005 - 9.00.1399.06 (Intel X86)
Oct 14 2005 00:33:37
Copyright (c) 1988-2005 Microsoft Corporation
Enterprise Edition on Windows NT 5.2 (Build 3790: Service Pack 1)
2008-04-18 15:47:46.59 Server (c) 2005 Microsoft Corporation.
2008-04-18 15:47:46.59 Server All rights reserved.
2008-04-18 15:47:46.59 Server Server process ID is 3984.
2008-04-18 15:47:46.59 Server Logging SQL Server messages in file ‘C:“Program Files“Microsoft SQL Server“MSSQL.1“MSSQL“LOG“ERRORLOG‘.
2008-04-18 15:47:46.59 Server This instance of SQL Server last reported using a process ID of 764 at 2008-4-18 15:46:40 (local) 2008-4-18 7:46:40 (UTC). This is an informational message only; no user action is required.
2008-04-18 15:47:46.60 Server Registry startup parameters:
2008-04-18 15:47:46.60 Server -d C:“Program Files“Microsoft SQL Server“MSSQL.1“MSSQL“DATA“master.mdf
2008-04-18 15:47:46.60 Server -e C:“Program Files“Microsoft SQL Server“MSSQL.1“MSSQL“LOG“ERRORLOG
2008-04-18 15:47:46.60 Server -l C:“Program Files“Microsoft SQL Server“MSSQL.1“MSSQL“DATA“mastlog.ldf
2008-04-18 15:47:46.62 Server Command Line Startup Parameters:
2008-04-18 15:47:46.62 Server -m2008-04-18 15:47:46.64 服務器 SQL Server is starting at normal priority base (=7). This is an informational message only. No user action is required.
2008-04-18 15:47:46.67 服務器 Detected 1 CPUs. This is an informational message; no user action is required.
2008-04-18 15:47:46.78 服務器 Using dynamic lock allocation. Initial allocation of 2500 Lock blocks and 5000 Lock Owner blocks per node. This is an informational message only. No user action is required.
2008-04-18 15:47:46.84 服務器 Attempting to initialize Microsoft Distributed Transaction Coordinator (MS DTC). This is an informational message only. No user action is required.
2008-04-18 15:47:47.95 服務器 Attempting to recover in-doubt distributed transactions involving Microsoft Distributed Transaction oordinator (MS DTC).
This is an informational message only. No user action is required.
2008-04-18 15:47:47.96 服務器 Database Mirroring Transport is disabled in the endpoint configuration.
2008-04-18 15:47:47.96 spid5s Warning ******************
2008-04-18 15:47:47.96 spid5s SQL Server started in single-user mode. This an informational message only. No user action is required.
2008-04-18 15:47:47.99 spid5s Starting up database ‘master‘.
2008-04-18 15:47:48.17 spid5s Recovery is writing a checkpoint in database ‘master‘ (1). This is an informational message only. No user action is required.
2008-04-18 15:47:48.28 spid5s SQL Trace ID 1 was started by login "sa".
2008-04-18 15:47:48.32 spid5s Starting up database ssqlsystemresource‘.
2008-04-18 15:47:48.76 spid5s Server name is ‘VM01‘. This is an informational message only. No user action is required.
2008-04-18 15:47:48.78 spid8s Starting up database ‘model‘.
2008-04-18 15:47:49.20 服務器 A self-generated certificate was successfully loaded for encryption.
2008-04-18 15:47:49.23 服務器 Server is listening on [ ‘any‘ <ipv4> 1433].
2008-04-18 15:47:49.24 服務器 Server local connection provider is ready to accept connection on [ ““.“pipe“SQLLocal“MSSQLSERVER ].
2008-04-18 15:47:49.24 服務器 Server local connection provider is ready to accept connection on [ ““.“pipe“sql“query ].
2008-04-18 15:47:49.28 服務器 Server is listening on [ 127.0.0.1 <ipv4>1434].
2008-04-18 15:47:49.28 服務器 Dedicated admin connection support was established for listening locally on port 1434.
2008-04-18 15:47:49.29 服務器 The SQL Network Interface library could not register the Service Principal Name (SPN) for the SQL Server service. Error: 0x54b. Failure to register an SPN may cause integrated authentication to fall back to NTLM instead of Kerberos. This is an informational message. Further action is only required if Kerberos authentication is required by authentication policies.
2008-04-18 15:47:49.31 服務器 SQL Server is now ready for client connections. This is an informational message; no user action is required.
2008-04-18 15:47:49.40 spid5s Starting up database ‘msdb‘.
2008-04-18 15:47:49.68 spid8s Clearing tempdb database.
2008-04-18 15:47:49.93 spid5s Recovery of any in-doubt distributed transactions involving Microsoft Distributed Transaction Coordinator (MS DTC) has completed. This is an informational message only. No user action is required.
2008-04-18 15:47:50.57 spid8s Starting up database ‘tempdb‘.
2008-04-18 15:47:50.76 spid5s Recovery is complete. This is an informational message only. No user action is required.
2008-04-18 15:56:22.34 spid51 SQL Trace was stopped due to server shutdown. Trace ID = ‘1‘. This is an informational message only; no user action is required.
2008-04-18 15:56:22.40 服務器 The SQL Network Interface library could not deregister the Service Principal Name (SPN) for the SQL Server service. Error: 0x54b. Administrator should deregister this SPN manually to avoid client authentication errors.
C:“Program Files“Microsoft SQL Server“MSSQL.1“MSSQL“Binn>
打開SSMS工具,先斷開連接,再新建查詢,執(zhí)行以下命名還原
USE master
GO
RESTORE DATABASE master
FROM disk=‘C:“Program Files“Microsoft SQL Server“MSSQL.1 “MSSQL“Backup“master.bak‘
GO
數(shù)據庫中的顯示的消息應為:
已為數(shù)據庫 ‘master‘,文件 ‘master‘ (位于文件 1 上)處理了 376 頁。
已為數(shù)據庫 ‘master‘,文件 ‘mastlog‘ (位于文件 1 上)處理了 6 頁。
已成功地還原了 master 數(shù)據庫。正在關閉 SQL Server。
SQL Server 正在終止此進程。
則表示master數(shù)據庫還原成功,啟動服務后進入SSMS即可看到master數(shù)據庫了
恢復master數(shù)據庫
方法一:(操作步驟)
1停止MSSQLSERVER服務
2命令行輸入:
net start "SQL Server (MSSQLSERVER)" /m
正常情況下顯示如下信息:
SQL Server (MSSQLSERVER) 服務正在啟動 ..
SQL Server (MSSQLSERVER) 服務已經啟動成功。
3命令行輸入:
sqlcmd
1>USE master;
2>GO
此時顯示:
已將數(shù)據庫上下文更改為 'master'。
1>RESTORE DATABASE master FROM DISK='數(shù)據庫備份文件路徑';
2>GO
如果恢復成功,顯示如下信息:
已為數(shù)據庫 'master',文件 'master' (位于文件 1 上)處理了 376 頁。
已為數(shù)據庫 'master',文件 'mastlog' (位于文件 1 上)處理了 3 頁。
已成功地還原了 master 數(shù)據庫。正在關閉 SQL Server。
SQL Server 正在終止此進程。
[/code]
失敗則顯示:
消息 3154,級別 16,狀態(tài) 4,服務器 HC,第 1 行
備份集中的數(shù)據庫備份與現(xiàn)有的 'master' 數(shù)據庫不同。
消息 3013,級別 16,狀態(tài) 1,服務器 HC,第 1 行
RESTORE DATABASE 正在異常終止。
此時需[/code]要在恢復語句后面加上:WITH REPLACE。如:
1>RESTORE DATABASE master FROM DISK=數(shù)據庫備份文件路徑' WITH REPLACE;
2>GO
[/code]
4重啟MSSQLSERVER服務
方法二:(與方法一差不多)
1打開“SQL Server 配置管理器”,單擊“SQL Server 服務”
2在右窗格中,右鍵單擊“SQL Server (<實例名>)”,再單擊“屬性”
3在“高級”選項卡的“啟動參數(shù)”框中,鍵入以分號“;”分隔的參數(shù)。(例如,若要以單用戶模式啟動,在現(xiàn)有啟動選項之前插入“-m;”,單擊“確定”,此時,彈出警告框,單擊“確定”即可)
4重新啟動數(shù)據庫引擎
5(同方法一中步驟3)
6成功恢復master數(shù)據庫后,若要以正常的多用戶模式重新啟動服務器實例,必須先從“啟動參數(shù)”框中刪除剛才輸入的“-m;”,然后重新啟動SQL Server服務
恢復msdb數(shù)據庫
在msdb數(shù)據庫里存儲較多的是SQL Agent里的內容,如作業(yè)、調度、操作員、警告等信息,同時還存放SQL Server Integration Service(SSIS)相關信息。其恢復過程與普通數(shù)據庫恢復過程大同小異,不同點就是需要在單用戶模式啟動下進行恢復。
1打開SQL Server Management Studio,連接到相關的數(shù)據庫服務器
2右鍵單擊msdb數(shù)據庫,單擊“屬性”打開數(shù)據庫屬性窗口,單擊“選項”,在右邊的“狀態(tài)”/“限制訪問”指定“SINGLE_USER”,然后單擊“確定”即以單用戶模式啟動,此時msdb顯示為“msdb(單個用戶)”
3(同恢復普通數(shù)據庫一樣...)
4恢復完畢后,別忘了將“限制訪問”改加以前的狀態(tài)“MULTI_USER”
相關文章
SQLServer2005安裝提示服務無法啟動原因分析及解決
安裝時出現(xiàn)了如下錯誤:SQL Server 2005 安裝錯誤碼29503,接下來講解一下,錯誤原因及解決方法,感興趣的你可以參考下,或許對你有所幫助2013-03-03
Sql Server安裝出錯,安裝程序配置服務器失敗的解決方法小結
機子之前有裝了sql server 2000,而且可以正常使用,最近突然無法連接到本地數(shù)據庫,打算重裝,結果重裝時出現(xiàn)了無法安裝完畢的問題,一下總結了重裝時需要注意的問題,以及常見錯誤的解決方法2012-10-10
簡單實用SQL腳本Part SQLServer 2005 鏈接服務器
SQL Server 2005版本的SSMS中已經有了 服務器對象->鏈接服務器 的功能點,用戶首先創(chuàng)建一個遠程DB的鏈接對象,之后就可以像本地表一樣執(zhí)行表的DML了。2010-09-09
在sqlserver2005中安裝sql server 2000的示例數(shù)據庫northwind的方法
裝完sql server 2005后卻沒有找到ms的示例數(shù)據庫northwind 后來查看安裝光盤發(fā)現(xiàn)sql server 2005種只有adventurework與adventureworkDW這兩個sample database 到ms官方站找了好久 才找到sql server 2000的sample database2013-05-05
SQL Server 使用 SET FMTONLY ON 獲得表的元數(shù)據
本文介紹SQL Server2005以及之后的版本,通過 SET FMTONLY ON 獲得表的元數(shù)據的方法,小伙伴們可以參考一下。2016-05-05
SQLSERVER 2005中使用sql語句對xml文件和其數(shù)據的進行操作(很全面)
由于數(shù)據庫對xml數(shù)據直接處理有很多優(yōu)勢,05也對這方面加強了功能。下面是一些實例代碼,大家可以參考下。2010-06-06
sql server 2005數(shù)據庫備份還原圖文教程
這篇文章主要介紹了sql server 2005數(shù)據庫備份還原圖文教程,為了方便大家這里提供的是詳細的圖文步驟,需要的朋友可以參考下2014-08-08

