备份和恢复DTS(本地包)的方法.

原创 2006年05月29日 13:41:00

备份的储存过程:

Save all DTS packages on server to files
Author Nigel Rivett

This will save all dts packages on the server to storage files.
It uses a trusted connect to access the package - just change the LoadFromSQLServer call to use a sql server connection.

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[s_SavePackages]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[s_SavePackages]
GO

Create procedure s_SavePackages
@Path	varchar(128)
as
/*

*/

	set nocount on

declare @objPackage int
declare @PackageName varchar(128)
declare @rc int
declare @ServerName varchar(128)
declare @FileName varchar(128)
declare	@FilePath varchar(128)
declare	@cmd varchar(2000)
	
	select 	@ServerName = @@ServerName ,
		@FilePath = @Path
	
	if right(@Path,1) <> '/'
	begin
		select @Path = @Path + '/'
	end
	
	-- create output directory - will fail if already exists but ...
	select	@cmd = 'mkdir ' + @FilePath
	exec master..xp_cmdshell @cmd
	
	
create table #packages (PackageName varchar(128))
	insert 	#packages
		(PackageName)
	select 	distinct name
	from	msdb..sysdtspackages
	
	select	@PackageName = ''
	while @PackageName < (select max(PackageName) from #packages)
	begin
		select	@PackageName = min(PackageName) from #packages where PackageName > @PackageName

		select	@FileName = @FilePath + @PackageName + '.dts'

		exec @rc = sp_OACreate 'DTS.Package', @objPackage output
		if @rc <> 0
		begin
			raiserror('failed to create package rc = %d', 16, -1, @rc)
			return
		end

		exec @rc = sp_OAMethod @objPackage, 'LoadFromSQLServer' , null,
			@ServerName = @ServerName, @Flags = 256, @PackageName = @PackageName
		if @rc <> 0
		begin
			raiserror('failed to load package rc = %d, package = %s', 16, -1, @rc, @PackageName)
			return
		end
		
		-- delete old file
		select @cmd = 'del ' + @FileName
		exec master..xp_cmdshell @cmd, no_output
		
		exec @rc = sp_OAMethod @objPackage, 'SaveToStorageFile', null, @FileName
		if @rc <> 0
		begin
			raiserror('failed to save package rc = %d, package = %s', 16, -1, @rc, @PackageName)
			return
		end
		
		exec @rc = sp_OADestroy @objPackage
	end
go
恢复的储存过程:
This will load the dts package from structured storage file @FileName and save to sql server (msdb) as @PackageName.


if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[s_LoadPackageToServer]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[s_LoadPackageToServer]
GO

Create procedure s_LoadPackageToServer
@PackageName	varchar(128) ,
@FileName	varchar(500) ,
@Username	varchar(100) ,
@Password	varchar(100)
as
/*
exec	s_LoadPackageToServer
		@PackageName = 'mypackage' ,
		@FileName = 'c:/dtspckgs/mypackage.dts' ,
		@Username = 'sa' ,
		@Password = 'pwd'
*/
declare @objPackage int
declare @rc int

		exec @rc = sp_OACreate 'DTS.Package', @objPackage output
		if @rc <> 0
		begin
			raiserror('failed to create package rc = %d', 16, -1, @rc)
			return
		end

		exec @rc = sp_OAMethod @objPackage, 'LoadFromStorageFile' , null,
			@UncFile = @FileName, @password = null
		if @rc <> 0
		begin
			raiserror('failed to load package rc = %d, package = %s', 16, -1, @rc, @PackageName)
			return
		end
		
		exec @rc = sp_OAMethod @objPackage, 'SaveToSQLServerAs' , null,
			@NewName = @PackageName, @ServerName = @@ServerName, @ServerUserName = @Username, @ServerPassword = @Password
		if @rc <> 0
		begin
			raiserror('failed to load package rc = %d, package = %s', 16, -1, @rc, @PackageName)
			return
		end
go

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

SQL2000 备份和恢复DTS(本地包)的方法

备份也可以通过打开包另存为dts文件完成。 Save all DTS packages on server to files Author Nigel Rivett This will sa...
  • riyao
  • riyao
  • 2012-05-22 10:29
  • 2918

DTS转立体声MP3方法

  • 2012-10-14 09:49
  • 916KB
  • 下载

(DT系列一)DTS结构及其编译方法

DTS结构及其编译方法 一:主要问题 1,需要了解dtsi与dts的关系 2,dts的结构模型 3,dts是如何被编译的,以及编译后会生成一个什么文件. 二:参考文字 1,...

用FFMPEG SDK进行视频转码压缩时解决音视频不同步问题的方法(转) PTS DTS

用FFMPEG SDK进行视频转码压缩的时候,转码成功后去看视频的内容,发现音视频是不同步的。这个的确是一个恼火的事情。我在用FFMPEG SDK做h264格式的FLV文件编码Filter的时候就碰到...

用FFMPEG SDK进行视频转码压缩时解决音视频不同步问题的方法(转) PTS DTS

用FFMPEG SDK进行视频转码压缩的时候,转码成功后去看视频的内容,发现音视频是不同步的。这个的确是一个恼火的事情。我在用FFMPEG SDK做h264格式的FLV文件编码Filter的时候就碰到...

dts的vb包转为delphi(0.01)

  • 2002-09-26 00:00
  • 149KB
  • 下载

pes时处理PTS和DTS的方法

PES包格式: 分组开始码前缀:0x00 0x00 0x01 流ID:视频为0x0E,音频为0x0C PES分组长度:这个包中此后数据的长度,包括此后剩余的PES包头长度...

用FFMPEG SDK进行视频转码压缩时解决音视频不同步问题的方法(转) PTS DTS

用FFMPEG SDK进行视频转码压缩的时候,转码成功后去看视频的内容,发现音视频是不同步的。这个的确是一个恼火的事情。我在用FFMPEG SDK做h264格式的FLV文件编码Filter的时候就碰到...
  • maopig
  • maopig
  • 2011-09-10 16:57
  • 5942
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)