sqlserver2005 master与msdb数据库备份恢复过程 |
由于系统数据库对Sql Server来说尤其重要,为了确保SQL SERVER系统的正常运行,除了日常备份用户的数据库之外,我们还需要备份系统数据库,如对Master,Model,Msdb(TempDB不需备份)进行完整备份 1、还原Master数据库 如果系统配置丢失或Master出现问题,可以进入单用户模式进行还原;如果出现下列情况,必须重新生成损坏的 master 数据库: 注意: 在 SQL Server 2005 中已废止 Rebuildm.exe 程序 。若要重新生成 master 数据库,请使用 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@!@ 2、 还原Master备份(在恢复master的备份时要注意:必须在单用户(single user)模式下进行 ) a.进入单用户模式的方法: 1.在命令行模式下输入sqlservr -c -f -m或者输入sqlservr -m 2.系统默认没有设置PATH,先进入CMD,进入“C:“Program Files“Microsoft SQL Server“MSSQL.1“MSSQL“Binn”,执行SQLSERVR.EXE –M 打开SSMS工具,先断开连接,再新建查询,执行以下命名还原 复制代码 代码如下: 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工具,先断开连接,再新建查询,执行以下命名还原 复制代码 代码如下: USE master GO RESTORE DATABASE master FROM disk=‘C:“Program Files“Microsoft SQL Server“MSSQL.1 “MSSQL“Backup“master.bak‘ GO 数据库中的显示的消息应为: 已为数据库 ‘master‘,文件 ‘master‘ (位于文件 1 上)处理了 376 页 。 恢复master数据库 方法一:(操作步骤) 1停止MSSQLSERVER服务 复制代码 代码如下: net start "SQL Server (MSSQLSERVER)" /m 正常情况下显示如下信息: 复制代码 代码如下: SQL Server (MSSQLSERVER) 服务正在启动 .. SQL Server (MSSQLSERVER) 服务已经启动成功 。 3命令行输入: 复制代码 代码如下: sqlcmd 1>USE master; 2>GO 此时显示: 复制代码 代码如下: 1>RESTORE DATABASE master FROM DISK=数据库备份文件路径; 2>GO 如果恢复成功,显示如下信息: 已为数据库 master,文件 master (位于文件 1 上)处理了 376 页 。 失败则显示: 复制代码 代码如下: 消息 3154,级别 16,状态 4,服务器 HC,第 1 行 备份集中的数据库备份与现有的 master 数据库不同 。 消息 3013,级别 16,状态 1,服务器 HC,第 1 行 RESTORE DATABASE 正在异常终止 。 此时需[/code]要在恢复语句后面加上:WITH REPLACE 。如: 1>RESTORE DATABASE master FROM DISK=数据库备份文件路径 WITH REPLACE; 4重启MSSQLSERVER服务 方法二:(与方法一差不多) 1打开“SQL Server 配置管理器”,单击“SQL Server 服务” 恢复msdb数据库 在msdb数据库里存储较多的是SQL Agent里的内容,如作业、调度、操作员、警告等信息,同时还存放SQL Server Integration Service(SSIS)相关信息 。其恢复过程与普通数据库恢复过程大同小异,不同点就是需要在单用户模式启动下进行恢复 。 1打开SQL Server Management Studio,连接到相关的数据库服务器 |