设为首页 加入收藏

TOP

SQLServer 批量备份与还原 (二)
2014-11-24 07:25:06 来源: 作者: 【 】 浏览:17
Tags:SQLServer 批量 备份 还原
到还原磁盘:'+@Drive+N' ,或者磁盘剩余空间小于1G'
RAISERROR50001@errorinfo
set@ResultCount=0
return
end
end
elseif(LEN(@RestoreDataPath)>1) ANDCHARINDEX(':',@RestoreDataPath)=0
begin
set@errorinfo=N'还原路径错误:'+@RestoreDataPath+N',必须包含":" 号'
Raiserror50001@errorinfo
set@ResultCount=0
return
end
set@ResultCount=1
end
GO

还原单个数据库

Usemaster
GO
/*=================Usp_RestoreDataBaseFormPath=======================================
=====Restore Single DataBase From a Back File ======
=====Ken.Guo ======
=====2010.9.10 ======
=====Version: 2005 & 2008 SQL Server ======
=====Usp_RestoreDataBaseFormPath 'D:\databack\dbcenter.bak','D:\Data',0 ======
=====Key Point Info: ======
--Restore HeaderOnly from disk='D:\data\xx.bak'
--Restore FileListOnly from disk='D:\data\xx.bak'
===================================================================================
*/
CREATEPROCUsp_RestoreDataBaseFormPath
(@DatabBaseBakPathnvarchar(400),
@RestoreDataPathnvarchar(400)='', --RESTORE DATABASE PATH
@IsRunsmallint=0-- 0 PRINT 1 run
)
AS
BEGIN
setnocount on

declare@dbnamenvarchar(200),@SQLnvarchar(4000),@DirSQLnvarchar(1000),@errorinfonvarchar(300)
--add path \
if(@RestoreDataPathisnotnull) andlen(@RestoreDataPath)>1
and(right(@RestoreDataPath,1)<>'\')
set@RestoreDataPath=@RestoreDataPath+'\'

declare@checkdriveint
set@checkdrive=1
execmaster.dbo.Usp_Check_DriveExists @RestoreDataPath,@checkdriveoutput

if(@checkdrive<>1)
GotoExitFLag

DECLARE@BakFileListTABLE
( LogicalName nvarchar(128)
,PhysicalName nvarchar(260)
)

DECLARE@BakHeaderInfoTABLE
(
DatabaseName nvarchar(128)
)

ifCharindex('Microsoft SQL Server 2008',@@VERSION)>0
begin
--SQL Server 2008
DECLARE@BakFileList2008TABLE
( LogicalName nvarchar(128)
,PhysicalName nvarchar(260)
,Type char(1)
,FileGroupName nvarchar(128)
,SIZE numeric(20,0)
,MaxSize numeric(20,0)
,FileID bigint
,CreateLSN numeric(25,0)
,DropLSN numeric(25,0) NULL
,UniqueID uniqueidentifier
,ReadOnlyLSN numeric(25,0) NULL
,ReadWriteLSN numeric(25,0) NULL
,BackupSizeInBytes bigint
,SourceBlockSize int
,FileGroupID int
,LogGroupGUID uniqueidentifierNULL
,DifferentialBaseLSN numeric(25,0) NULL
,DifferentialBaseGUID uniqueidentifier
,IsReadOnly bit
,IsPresent bit
,TDEThumbprint varbinary(32)
)

INSERTINTO@BakFileList2008
EXECsp_executesql N'Restore FileListOnly From Disk=@DatabBaseBakPath',N'@DatabBaseBakPath nvarchar(260)',@DatabBaseBakPath

DECLARE@BakHeaderInfo2008TABLE
(
BackupName nvarchar(128)
,BackupDescription nvarchar(255)
,BackupType smallint
,ExpirationDate datetime
,Compressed tinyint
,POSITION smallint
,DeviceType tinyint
,UserName nvarchar(128)
,ServerNam

首页 上一页 1 2 3 4 5 6 下一页 尾页 2/6/6
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇sql server批量插入与更新两种解.. 下一篇SQL Server数据库中批量导入数据

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·PostgreSQL 索引 - (2025-12-25 22:20:43)
·MySQL Node.js 连接 (2025-12-25 22:20:41)
·SQL 撤销索引、表以 (2025-12-25 22:20:38)
·Linux系统简介 (2025-12-25 21:55:25)
·Linux安装MySQL过程 (2025-12-25 21:55:22)