sql server 2005 2008 master和msdb数据库的备份与恢复,master和msdb数据库的备份与普通数据库相同。本文主要讲述一些个人积累的master和msdb数据库的恢复。
恢复master和msdb数据库的关键是在单用户模式下启动,其他没有太大区别。
由于系统数据库对sql server尤为重要,为了保证SQL SERVER系统的正常运行,我们除了需要备份用户的日常数据库之外,还需要备份系统数据库,比如Master、Model、
Msdb(TempDB不需要备份)进行完整备份。
1.还原主数据库
如果系统配置丢失或者Master有问题,可以进入单用户模式恢复;在下列情况下,必须重新生成损坏的主数据库:
A.主数据库的当前备份不可用。
b . master数据库的备份存在,但无法还原,因为无法启动Microsoft SQL Server实例。
1.重新生成主数据库:
注意:
Rebuildm.exe程序在sql server 2005中已被废除。要重建主数据库,请使用setup.exe。
1、启动/等待setup.exe/qn实例名=实例名重新安装=SQL _ Engine重建数据库=1 sa pwd=NewStrongPassword
例:开始/等待e:"设置。exe/qn实例名=MSSQL server REINSTALL=SQL _ Engine重建数据库=1 sa pwd=ABC 123 @!@
注意:INSTANCENAME:指定实例名,默认实例用mssqlserver表示。
重新安装:指定引擎
SAPWD:强密码
Setup.exe:指定CD 1中根目录下的文件。
/qn开关用于取消所有安装程序对话框和错误消息。如果指定/qn开关,所有安装程序消息(包括错误消息)都将写入安装程序日志文件。有关日志文件的更多信息,
请参阅如何查看SQL Server 2005安装日志文件。
指定/qb开关将显示基本安装程序对话框。还会显示一条错误消息。
2.恢复主服务器的备份(恢复主服务器的备份时:必须在单用户模式下进行)a .如何进入单用户模式:
1.在命令行模式下输入sqlservr -c -f -m或sqlservr -m。
其中:-c 可以缩短启动时间,SQL Server 不作为Windows NT的服务启动
-f 用最小配置启动SQL Server
-m 单用户模式启动SQL Server
2.系统默认没有设置PATH,先进入CMD,进入“C:“Program Files“Microsoft SQL Server“MSSQL.1“MSSQL“Binn”,执行SQLSERVR.EXE M
打开SSMS工具,先断开连接,再新建查询,执行以下命名还原
USE master
GO
RESTORE DATABASE master
FROM disk=‘c:“master.bak‘
GO
开始实验了~~~
MASTER重新生成
为了模拟MASTER数据库坏了,我们就删除MASTER数据库(要停止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
连接到数据库后就可以发现数据库中的数据又回来了
以下是我在命令行下搞的命令,我用记事本的方式全部复制下来了,为了不传附件,我就直接粘贴到下面了
Microsoft Windows [版本5.2.3790]
(C) 版权所有1985-2003 Microsoft Corp.
C:“Documents and Settings“Administratorstart /wait e:“setup.exe /qn INSTANCENAME=mssqlserver REINSTALL=SQL_Engine REBUILDDATABASE=1 SAPWD=abc123@!@
C:“Documents and Settings“Administratorcd C:“Program Files“Microsoft SQL Server“MSSQL.1“MSSQL“Binn
C:“Program Files“Microsoft SQL Server“MSSQL.1“MSSQL“Binnsqlservr.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 wa