SQL SERVER 2005 Master备份与还原

本文涉及的产品
云数据库 RDS SQL Server,独享型 2核4GB
简介: 版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/chinahuyong/article/details/3551837  一、...
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/chinahuyong/article/details/3551837
 
一、备份Master 及相关的系统数据库
由于系统数据库对Sql Server来说尤其重要,为了确保SQL SERVER系统的正常运行,除了日常备份用户的数据库之外,我们还需要备份系统数据库,如对MasterModelMsdbTempDB不需备份)进行完整备份
二、还原Master数据库
如果系统配置丢失或Master出现问题,可以进入单用户模式进行还原; 如果出现下列情况,必须重新生成损坏的 master 数据库:<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

A.       master 数据库的当前备份不可用。

B.        存在 master 数据库备份,但由于 Microsoft SQL Server 实例无法启动,因此无法还原该备份。
1、重新生成 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@!@
注:INSTANCENAME:指定实例名,默认实例则用mssqlserver表示
REINSTALL:指定引擎
SAPWD:强密码
Setup.exe:指定光盘1中的根目录下的文件
/qn 开关用于取消所有安装程序对话框和错误消息。如果指定 /qn 开关,则所有安装程序消息(包括错误消息)都将写入安装程序日志文件。有关日志文件的详细信息,请参阅如何查看 SQL Server 2005 安装日志文件。

 

指定 /qb 开关将显示基本的安装程序对话框。还会显示错误消息。
     
2、 还原Master备份

先进入单用户模式,系统默认没有设置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/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            -m
2008-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',文件 'mastlog' (位于文件 1 上)处理了 6 页。
已成功地还原了 master 数据库。正在关闭 SQL Server。
SQL Server 正在终止此进程。
   则表示master数据库还原成功,启动服务后进入SSMS即可看到master数据库了 ^ ^
相关实践学习
使用SQL语句管理索引
本次实验主要介绍如何在RDS-SQLServer数据库中,使用SQL语句管理索引。
SQL Server on Linux入门教程
SQL Server数据库一直只提供Windows下的版本。2016年微软宣布推出可运行在Linux系统下的SQL Server数据库,该版本目前还是早期预览版本。本课程主要介绍SQLServer On Linux的基本知识。 相关的阿里云产品:云数据库RDS&nbsp;SQL Server版 RDS SQL Server不仅拥有高可用架构和任意时间点的数据恢复功能,强力支撑各种企业应用,同时也包含了微软的License费用,减少额外支出。 了解产品详情:&nbsp;https://www.aliyun.com/product/rds/sqlserver
相关文章
|
4天前
|
SQL 存储 数据库连接
LabVIEW与SQL Server 2919 Express通讯
LabVIEW与SQL Server 2919 Express通讯
|
5天前
|
SQL Windows
安装SQL Server 2005时出现对性能监视器计数器注册表值执行系统配置检查失败的解决办法...
安装SQL Server 2005时出现对性能监视器计数器注册表值执行系统配置检查失败的解决办法...
13 4
|
6天前
|
SQL 数据可视化 Oracle
这篇文章教会你:从 SQL Server 移植到 DM(上)
这篇文章教会你:从 SQL Server 移植到 DM(上)
|
6天前
|
SQL 关系型数据库 数据库
SQL Server语法基础:入门到精通
SQL Server语法基础:入门到精通
SQL Server语法基础:入门到精通
|
6天前
|
SQL 存储 网络协议
SQL Server详细使用教程
SQL Server详细使用教程
30 2
|
6天前
|
SQL 存储 数据库连接
C#SQL Server数据库基本操作(增、删、改、查)
C#SQL Server数据库基本操作(增、删、改、查)
7 0
|
6天前
|
SQL 存储 小程序
数据库数据恢复—Sql Server数据库文件丢失的数据恢复案例
数据库数据恢复环境: 5块硬盘组建一组RAID5阵列,划分LUN供windows系统服务器使用。windows系统服务器内运行了Sql Server数据库,存储空间在操作系统层面划分了三个逻辑分区。 数据库故障: 数据库文件丢失,主要涉及3个数据库,数千张表。数据库文件丢失原因未知,不能确定丢失的数据库文件的存放位置。数据库文件丢失后,服务器仍处于开机状态,所幸未写入大量数据。
数据库数据恢复—Sql Server数据库文件丢失的数据恢复案例
|
7天前
|
SQL 存储 关系型数据库
SQL Server详细使用教程及常见问题解决
SQL Server详细使用教程及常见问题解决
|
8天前
|
SQL 安全 数据库
SQL Server 备份和还原
SQL Server 备份和还原
|
存储 SQL 程序员
【Sql Server】存储过程通过作业定时执行按天统计记录
通过前两篇文章的学习,我们已经对创建表、存储过程、作业等功能点有所了解 本次将结合前面所学习的知识点,创建统计表以及结合作业定时按天以及实时统计域名各个长度的记录值
312 0
【Sql Server】存储过程通过作业定时执行按天统计记录