Free Newsletters:
DatabaseJournal  
DBANews
Search Database Journal:
 
HOME News MS SQL Oracle DB2 Access MySQL PostgreSQL PHP SQL Etc Scripts Links Discussion
internet.com

» HOME
» NEWS
» FEATURES
» SERIES
MS SQL
Oracle
MS Access
MySQL
DB2
» RESOURCES
Products
Scripts
Links
» DISCUSSION
» TECH JOBS

Marketplace Partners
Be a Marketplace Partner




internet.commerce
Be a Commerce Partner
Find Software
Boat Donations
Prepaid Phone Card
Shop
Memory Upgrades
Promotional Golf
Logo Design
Shop Online
Auto Insurance Quote
Compare Prices
Domain registration
PDA Phones & Cases
Promote Your Website
Calling Cards




Google Display Ads in Your Pocket

Ballmer Ready to Move on Yahoo?

Acer Strong in Q1 With Aggressive Growth

internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers


Linked Data Planet Conference & Expo

CA ERwin® Data Modeler Proven database design and modeling. Efficiently analyze, design and deploy effective database solutions. Whitepaper: Manage SQL Server Deployments
Try it free: CA ERwin® Data Modeler


Solaris 8 Migration Assistant
Rapidly move your Solaris 8 application environments to new systems running Solaris 10 with the Solaris 8 Migration Assistant. Reduce migration risk while taking advantage of increased performance, reliability and security of the latest SPARC hardware platforms and Solaris 10 OS. »

 
Sun Eco Innovation: Good for Business, Good for the Environment
A complete solution to help you optimize and refresh your datacenter while properly recycling equipment and eliminating eWaste, including money-saving promotions to lower hardware acquisition costs. »

 
Sun Eco Innovation: Power Calculators
Power consumption has increasingly become a priority in customer's minds when purchasing new systems or storage. Sun's Power Calculators provide data on power consumption of Sun products allowing IT managers to better plan the power requirements in the datacenter to achieve better energy and cost savings. »

 
Optimize the Web Tier: Consolidate to Get More Performance in Less Space and Lower Power Consumption
Expansion in the Web tier is generally accomplished by adding more servers whenever extra capacity is needed. As the pool of servers grows larger, however, the complexity of the environment can grow exponentially. »

Production Manager (hands on)
Aquent
US-MA-Cambridge

Justtechjobs.com Post A Job | Post A Resume
MS SQL
March 20, 2008
Using dtutil to copy SSIS packages stored in SQL Server
By Yan Pan

In this article, we are going to discuss how to copy SSIS packages stored in SQL Server and their associated package roles using the dtutil command line utility.

SSIS packages can be saved in three types of storage locations: SQL Server, File System, and SSIS Package Store. When an SSIS package is saved into SQL Server, it is saved in the msdb database, specifically, the dbo.sysdtspackages90 table in msdb. There are many advantages of saving SSIS packages in SQL Server vs. in FileSystem or SSIS package Store (which is a special file system location in Program Files\Microsoft SQL Server\90\DTS\Packages). When packages are saved in SQL Server, they can be backed up with the normal msdb database backup process. The access to the packages can be controlled by the security mechanism built into SQL Server through database roles. The packages are also easy to query using T-SQL. In one word, SQL Server is the better storage option for production environments.

However, packages stored in SQL Server are not as portable as the ones stored in files. To copy a package stored in a file, you can simply copy the file from one machine to another. To copy a package stored in SQL Server from one server to another, you will need to use the Import and Export package feature in SQL Server Management Studio (SSMS) or the dtutil command line utility. The Import and Export package feature in SSMS is GUI-based. It cannot be used to copy or move multiple packages at the same time. The dtuil command, however, can be incorporated into a script to handle multiple packages in a batch.

When copying SSIS packages, we also need to copy the security permissions associated with the packages. The access to packages stored in SQL Server is controlled by database roles in the msdb database, including the three fixed database-level roles db_dtsadmin, db_dtsltduser, and db_dtsoperator. By default, the permissions of the db_dtsadmin, db_dtsltduser, and db_dtsoperator fixed database-level roles apply to the reader role for packages, and the permissions of the db_dtsadmin role apply to the writer role. However, you can change the default behavior by using SSMS. For example, if you want everyone in the db_datareader to be able to view a package, you can map the reader role of the package to db_datareader. When we copy a package to another server, we also need to copy its reader and writer roles. On a side note, because you can only connect to Integration Services with Windows authentication, these roles only apply to Windows logins in most cases.

Let’s first look at a scenario in which the packages are stored in SQL Server with the “Rely on server storage and roles for access control” protection level. This means, the contents of the packages are only protected by the database roles. The copySSISpackages.sql script shown below creates a stored procedure called copySSISpackages. The stored procedure accepts parameters of the connection information to a source server and a destination server, and then generates a script that can be used to copy SSIS packages from the source server to the destination server.

--=====================================================================
-- Author:  Yan Pan
-- Description: This stored procedure is used to generate a script 
-- for all the SSIS package stored in a SQL Server 
-- that are only protected by database roles.
-- The output script can be executed on another server 
-- to copy SSIS packages from the source server.
--=====================================================================
USE msdb
IF  EXISTS (SELECT * FROM sys.objects 
  WHERE object_id = OBJECT_ID(N'[dbo].[copySSISpackages]') AND type in (N'P', N'PC'))
DROP PROCEDURE dbo.copySSISpackages
GO
CREATE PROCEDURE dbo.copySSISpackages 
@srcServer sysname, -- Source server name
@destServer sysname, -- Destination server name
@srcUser sysname = '', -- SQL Server login used to connect to the source server
@srcPassword sysname = '', -- Password of the SQL Server login on the source server
@destUser sysname = '', -- SQL Server login used to connect to the destination server
@destPassword sysname = '' -- Password of the SQL Server login on the destination server
AS
BEGIN
  SET NOCOUNT ON;
  
  print 'USE msdb'
 
  -- Copy SSIS packages
  select 'EXEC [master].[sys].[xp_cmdshell] ''dtutil /Quiet /COPY SQL;' + 
  case foldername when '' then '"' + [name] + '"' else '"' + foldername + '\' +  [name] + '"' end 
  + ' /SQL ' + case foldername when '' then '"' + [name] + '"' else '"' + foldername + '\' +  [name] + '"' end 
  + ' /SOURCESERVER ' + @srcServer 
  + case @srcUser when '' then '' else ' /SourceUser ' + @srcUser + ' /SourcePassword ' + @srcPassword end
  + ' /DESTSERVER ' + @destServer
  + case @destUser when '' then '' else ' /DestUser ' + @destUser + ' /DestPassword ' + @destPassword end + ''''
  from msdb.dbo.sysdtspackages90 pkg join msdb.dbo.sysdtspackagefolders90 fld
  on pkg.folderid = fld.folderid
 
  -- Copy SSIS package roles
  select 'EXEC [dbo].[sp_dts_setpackageroles] @name = ''' + pkg.[name] + ''', '
  + '@folderid = ''' + CONVERT(CHAR(36), folderid) + ''', @readrole = ' + isNull('''' + p1.[name] + '''', 'NULL') + ',  '
     + '@writerole = ' + isNull('''' + p2.[name] + '''', 'NULL') 
  FROM msdb.dbo.sysdtspackages90 pkg 
  left join sys.database_principals p1 on p1.sid = pkg.readrolesid and p1.[type] = 'R'
  left join sys.database_principals p2 on p2.sid = pkg.writerolesid and p2.[type] = 'R' 
END
GO

For example, we would like to copy the packages from the default instance on the host PowerPC to the named instance INSTANCE1 on the same host. On the default instance PowerPC, there are three SSIS packages – CreateLists, ImportCustomers, and BackupUserDB under Maintenance Plans (see Figure 1). The CreateLists package has the db_datareader role as the reader role, and db_datawriter as the writer role. The other two packages have the default package roles.


Figure 1: Three SSIS packages exist on default instance.

We run the copySSISpackages.sql script on the default instance PowerPC and create the copySSISpackages stored procedure in msdb. Then we execute the stored procedure.

exec dbo.copySSISpackages 'PowerPC', 'PowerPC\INSTANCE1'

We are using Windows authentication with dtutil here. Therefore, we don’t need to pass the user names and passwords. You can also choose to use SQL Server authentication. The output script from the stored procedure is shown here.

USE msdb
-----------------------------------------------------------------------------------------------------------------------------
EXEC [master].[sys].[xp_cmdshell] 'dtutil /Quiet /COPY SQL;"CreateLists" /SQL "CreateLists" 
  /SOURCESERVER PowerPC /DESTSERVER PowerPC\INSTANCE1'
EXEC [master].[sys].[xp_cmdshell] 'dtutil /Quiet /COPY SQL;"ImportCustomers" /SQL "ImportCustomers" 
  /SOURCESERVER PowerPC /DESTSERVER PowerPC\INSTANCE1'
EXEC [master].[sys].[xp_cmdshell] 'dtutil /Quiet /COPY SQL;"Maintenance Plans\BackupUserDB" /SQL "Maintenance Plans\BackupUserDB" 
  /SOURCESERVER PowerPC /DESTSERVER PowerPC\INSTANCE1'

-------------------------------------------------------------------------------------------------------------------------------
EXEC [dbo].[sp_dts_setpackageroles] @name = 'CreateLists', @folderid = '00000000-0000-0000-0000-000000000000', 
  @readrole = 'db_datareader',  @writerole = 'db_datawriter'

EXEC [dbo].[sp_dts_setpackageroles] @name = 'ImportCustomers', @folderid = '00000000-0000-0000-0000-000000000000', 
  @readrole = NULL,  @writerole = NULL
EXEC [dbo].[sp_dts_setpackageroles] @name = 'BackupUserDB', @folderid = '08AA12D5-8F98-4DAB-A4FC-980B150A5DC8', 
  @readrole = NULL,  @writerole = NULL

Copy the output script and run it on the named instance PowerPC\INSTANCE1. All three packages are copied successfully (see Figure 2).


Figure 2: All three packages are copied to the named instance INSTANCE1 successfully.

If the xp_cmdshell option is disabled on the destination server, you will not be able to run the output script. Run the following statements to enable the option.

EXEC sp_configure 'show advanced options', 1
RECONFIGURE
EXEC sp_configure 'xp_cmdshell', 1
RECONFIGURE

In addition to database roles, SSIS packages stored in SQL Server can also be protected with a user key or a password. Package data encrypted with a user key is encrypted with a key based on the user who created or imported the package. Only the user who created the package will be able to run the package. This is not very useful for a production environment. Therefore, in production environments, the entire SSIS package is usually protected with a password. Let’s consider a slightly different scenario in which all packages stored in SQL Server are protected with a password for both security and convenience. In this case, we need to modify the copySSISpackages.sql script to include the “Encrypt” and “Decrypt” options in the dtutil commands. The new script copySSISpackages_encryptedByPwd.sql is shown below. It creates a new stored procedure called copySSISpackages_encryptedByPwd.

--=====================================================================
-- Author:  Yan Pan
-- Description: This stored procedure is used to generate a script 
-- for all the SSIS package stored in a SQL Server 
-- that are protected by both database roles and a common password.
-- The output script can be executed on another server 
-- to copy SSIS packages from the source server.
--=====================================================================
USE msdb
IF  EXISTS (SELECT * FROM sys.objects 
  WHERE object_id = OBJECT_ID(N'[dbo].copySSISpackages_encryptedByPwd') AND type in (N'P', N'PC'))
DROP PROCEDURE dbo.copySSISpackages_encryptedByPwd
GO
CREATE PROCEDURE dbo.copySSISpackages_encryptedByPwd
  @srcServer sysname, -- Source server name
  @destServer sysname, -- Destination server name
  @oldPassword varchar(20), -- The password used to encrypt SSIS packages on the source server
  @newPassword varchar(20), -- The password used to encrypt SSIS packages on the destination server
  @srcUser sysname = '', -- SQL Server login used to connect to the source server
  @srcPassword sysname = '', -- Password of the SQL Server login on the source server
  @destUser sysname = '', -- SQL Server login used to connect to the destination server
  @destPassword sysname = '' -- Password of the SQL Server login on the destination server
AS
BEGIN
  SET NOCOUNT ON;
 
  print 'USE msdb'
 
  -- Copy SSIS packages
  select 'EXEC [master].[sys].[xp_cmdshell] ''dtutil /Quiet /COPY SQL;' + 
  case foldername when '' then '"' + [name] + '"' else '"' + foldername + '\' +  [name] + '"' end 
  + ' /SQL ' + case foldername when '' then '"' + [name] + '"' else '"' + foldername + '\' +  [name] + '"' end
  + ' /SOURCESERVER ' + @srcServer 
  + case @srcUser when '' then '' else ' /SourceUser ' + @srcUser + ' /SourcePassword ' + @srcPassword end
  + ' /DESTSERVER ' + @destServer
  + case @destUser when '' then '' else ' /DestUser ' + @destUser + ' /DestPassword ' + @destPassword end 
  + ' /Decrypt ' + @oldPassword + ''''
  from msdb.dbo.sysdtspackages90 pkg join msdb.dbo.sysdtspackagefolders90 fld
  on pkg.folderid = fld.folderid
 
  -- Change the encryption password from @oldPassword to @newPassword on the destination server
  select 'EXEC [master].[sys].[xp_cmdshell] ''dtutil /Quiet /SQL ' + 
  case foldername when '' then '"' + [name] + '"' else '"' + foldername + '\' +  [name] + '"' end 
  + ' /SOURCESERVER ' + @destServer 
  + ' /DESTSERVER ' + @destServer + ' /Decrypt ' + @oldPassword + ' /Encrypt SQL;' + 
  case foldername when '' then '"' + [name] + '"' else '"' + foldername + '\' +  [name] + '"' end
  + ';3;' + @newPassword + ''''
  from msdb.dbo.sysdtspackages90 pkg join msdb.dbo.sysdtspackagefolders90 fld
  on pkg.folderid = fld.folderid
 
  -- Copy SSIS package roles
  select 'EXEC [dbo].[sp_dts_setpackageroles] @name = ''' + pkg.[name] + ''', '
  + '@folderid = ''' + CONVERT(CHAR(36), folderid) + ''', @readrole = ' + isNull('''' + p1.[name] + '''', 'NULL') + ',  '
     + '@writerole = ' + isNull('''' + p2.[name] + '''', 'NULL') 
  FROM msdb.dbo.sysdtspackages90 pkg 
  left join sys.database_principals p1 on p1.sid = pkg.readrolesid and p1.[type] = 'R'
  left join sys.database_principals p2 on p2.sid = pkg.writerolesid and p2.[type] = 'R' 
END
GO

Let’s assume the three packages in our example above are encrypted by a password “oldpwd”. We want to copy them from the default instance PowerPC to the name instance PowerPC\INSTANCE1 and then encrypt them with a new password “newpwd”. We run the copySSISpackages_encryptedByPwd.sql script on the default instance PowerPC and create the copySSISpackages_encryptedByPwd stored procedure in msdb. Then we execute the stored procedure.

exec dbo.copySSISpackages_encryptedByPwd 'PowerPC', 'PowerPC\INSTANCE1', 'oldpwd', 'newpwd'

The output script is shown here.

USE msdb
-------------------------------------------------------------------------------------------------------------------------------
EXEC [master].[sys].[xp_cmdshell] 'dtutil /Quiet /COPY SQL;"CreateLists" /SQL "CreateLists" 
  /SOURCESERVER PowerPC /DESTSERVER PowerPC\INSTANCE1 /Decrypt oldpwd'
EXEC [master].[sys].[xp_cmdshell] 'dtutil /Quiet /COPY SQL;"ImportCustomers" /SQL "ImportCustomers" 
  /SOURCESERVER PowerPC /DESTSERVER PowerPC\INSTANCE1 /Decrypt oldpwd'
EXEC [master].[sys].[xp_cmdshell] 'dtutil /Quiet /COPY SQL;"Maintenance Plans\BackupUserDB" 
  /SQL "Maintenance Plans\BackupUserDB" /SOURCESERVER PowerPC /DESTSERVER PowerPC\INSTANCE1 /Decrypt oldpwd'

--------------------------------------------------------------------------------------------------------------------------------
EXEC [master].[sys].[xp_cmdshell] 'dtutil /Quiet /SQL "CreateLists" /SOURCESERVER PowerPC\INSTANCE1 
  /DESTSERVER PowerPC\INSTANCE1 /Decrypt oldpwd /Encrypt SQL;"CreateLists";3;newpwd'
EXEC [master].[sys].[xp_cmdshell] 'dtutil /Quiet /SQL "ImportCustomers" /SOURCESERVER PowerPC\INSTANCE1 
  /DESTSERVER PowerPC\INSTANCE1 /Decrypt oldpwd /Encrypt SQL;"ImportCustomers";3;newpwd'
EXEC [master].[sys].[xp_cmdshell] 'dtutil /Quiet /SQL "Maintenance Plans\BackupUserDB" 
  /SOURCESERVER PowerPC\INSTANCE1 /DESTSERVER PowerPC\INSTANCE1 
    /Decrypt oldpwd /Encrypt SQL;"Maintenance Plans\BackupUserDB";3;newpwd'

--------------------------------------------------------------------------------------------------------------------------------
EXEC [dbo].[sp_dts_setpackageroles] @name = 'BackupUserDB', @folderid = '08AA12D5-8F98-4DAB-A4FC-980B150A5DC8', 
  @readrole = NULL,  @writerole = NULL
EXEC [dbo].[sp_dts_setpackageroles] @name = 'CreateLists', @folderid = '00000000-0000-0000-0000-000000000000', 
  @readrole = 'db_datareader',  @writerole = 'db_datawriter'
EXEC [dbo].[sp_dts_setpackageroles] @name = 'ImportCustomers', @folderid = '00000000-0000-0000-0000-000000000000', 
  @readrole = NULL,  @writerole = NULL

As you can see, the script first copies the three packages with the “Decrypt” option and the decryption password “oldpwd”. Then it encrypts the packages with the new password “newpwd”. After that, it copies the package roles.

Conclusion

This article has illustrated how to copy SSIS packages stored in SQL Server and package roles between SQL Server 2005 instances.

» See All Articles by Columnist Yan Pan

Tools:
Add databasejournal.com to your favorites
Add databasejournal.com to your browser search box
IE 7 | Firefox 2.0 | Firefox 1.5.x
Receive news via our XML/RSS feed

MS SQL Archives

Webcast: Five Virtualization Trends to Watch. Produced for HP, Citrix, and Intel.
Five Trends for Application Development. Download Your Complimentary Report. Exclusive. Act Now.
Download: SQL Compare Pro 6--The fastest, easiest way to compare and synchronize two databases.
Flash Demo: Learn how IBM Information Server Blade is easy to manage, highly scalable and efficient.
Five Trends for Application Development & Program Management. Download Complimentary Report Now.


Latest Forum Threads
MS SQL Forum
Topic By Replies Updated
How To Transfer Access Data Records To SQL ?? ankurdjariwala 1 May 8th, 12:24 PM
problem with federated server linking majidkhan 1 April 29th, 10:00 AM
"SELECT rowguidcol" from tables on linked servers? brentbordelon 1 April 25th, 04:12 PM
"SELECT rowguidcol" vs. "SELECT <actual name>" rgarrison 9 April 16th, 03:46 PM







JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
Microsoft Article: HyperV-The Killer Feature in WinServer ‘08
Avaya Article: How to Feed Data into the Avaya Event Processor
Microsoft Article: Install What You Need with Win Server ‘08
HP eBook: Putting the Green into IT
Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
Avaya Article: Setting Up a SIP A/S Development Environment
IBM Article: How Cool Is Your Data Center?
Microsoft Article: Managing Virtual Machines with Microsoft System Center
HP eBook: Storage Networking , Part 1
Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Intel Video: Are Multi-core Processors Here to Stay?
On-Demand Webcast: Five Virtualization Trends to Watch
HP Video: Page Cost Calculator
Intel Video: APIs for Parallel Programming
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Sun Download: Solaris 8 Migration Assistant
Sybase Download: SQL Anywhere Developer Edition
Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
Red Gate Download: SQL Compare Pro 6
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
IBM Article: Collaborating in the High-Performance Workplace
HP Demo: StorageWorks EVA4400
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES