<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>extract Archives | ZappySys Blog</title>
	<atom:link href="https://zappysys.com/blog/tag/extract/feed/" rel="self" type="application/rss+xml" />
	<link>https://zappysys.com/blog/tag/extract/</link>
	<description>SSIS / ODBC Drivers / API Connectors for JSON, XML, Azure, Amazon AWS, Salesforce, MongoDB and more</description>
	<lastBuildDate>Thu, 22 Dec 2016 06:04:34 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.4.4</generator>

<image>
	<url>https://zappysys.com/blog/wp-content/uploads/2023/01/cropped-zappysys-symbol-large-32x32.png</url>
	<title>extract Archives | ZappySys Blog</title>
	<link>https://zappysys.com/blog/tag/extract/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Extract / Unload Redshift data into SQL Server using SSIS</title>
		<link>https://zappysys.com/blog/extract-unload-redshift-data-sql-server-using-ssis/</link>
		
		<dc:creator><![CDATA[ZappySys]]></dc:creator>
		<pubDate>Tue, 27 Oct 2015 19:55:36 +0000</pubDate>
				<category><![CDATA[AWS (Amazon Web Services)]]></category>
		<category><![CDATA[Cloud Computing]]></category>
		<category><![CDATA[Redshift]]></category>
		<category><![CDATA[amazon]]></category>
		<category><![CDATA[aws]]></category>
		<category><![CDATA[big data]]></category>
		<category><![CDATA[cloud computing]]></category>
		<category><![CDATA[etl]]></category>
		<category><![CDATA[extract]]></category>
		<category><![CDATA[redshift]]></category>
		<category><![CDATA[s3]]></category>
		<category><![CDATA[ssis]]></category>
		<category><![CDATA[SSIS PowerPack]]></category>
		<guid isPermaLink="false">http://zappysys.com/blog/?p=128</guid>

					<description><![CDATA[<p>Introduction In our previous article we saw how to load data into Redshift using SSIS or load data into Redshift using ZappyShell Redshift Command Line In this article we will walk through various steps to Extract/UNLOAD Redshift Data into SQL Server using Amazon S3 Storage Task and ExecuteSQL Task for Amazon Redshift. Below is the [&#8230;]</p>
<p>The post <a href="https://zappysys.com/blog/extract-unload-redshift-data-sql-server-using-ssis/">Extract / Unload Redshift data into SQL Server using SSIS</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2>Introduction</h2>
<p>In our previous article we saw <a href="//zappysys.com/posts/sql-server-to-redshift-data-load-using-ssis/">how to load data into Redshift using SSIS</a> or load data into Redshift using ZappyShell <a href="//zappysys.com/products/zappyshell/amazon-redshift-command-line-tools/">Redshift Command Line</a></p>
<p>In this article we will walk through various steps to <em>Extract/UNLOAD Redshift Data into SQL Server</em> using <a href="//zappysys.com/products/ssis-powerpack/ssis-amazon-s3-task/">Amazon S3 Storage Task</a> and <a href="//zappysys.com/products/ssis-powerpack/ssis-redshift-execute-sql-task/">ExecuteSQL Task for Amazon Redshift</a>. Below is the screenshot of actual SSIS Package to <em>Extract Redshift Data and Load into SQL Server</em></p>
<div id="attachment_164" style="width: 664px" class="wp-caption alignnone"><a href="//zappysys.com/blog/wp-content/uploads/2015/10/extract-unload-redshift-data-load-to-sql-server-ssis.png"><img fetchpriority="high" decoding="async" aria-describedby="caption-attachment-164" class="size-full wp-image-164" src="//zappysys.com/blog/wp-content/uploads/2015/10/extract-unload-redshift-data-load-to-sql-server-ssis.png" alt="Extract/Unload Redshift Data using SSIS and Load into SQL Server" width="654" height="565" srcset="https://zappysys.com/blog/wp-content/uploads/2015/10/extract-unload-redshift-data-load-to-sql-server-ssis.png 654w, https://zappysys.com/blog/wp-content/uploads/2015/10/extract-unload-redshift-data-load-to-sql-server-ssis-300x259.png 300w" sizes="(max-width: 654px) 100vw, 654px" /></a><p id="caption-attachment-164" class="wp-caption-text">Extract/Unload Redshift Data using SSIS and Load into SQL Server</p></div>
<h2>Requirements for Extract Redshift Data using SSIS</h2>
<p>Before you <a href="http://docs.aws.amazon.com/redshift/latest/dg/r_UNLOAD.html">UNLOAD</a> data from Redshift, you have to make sure few things.</p>
<ol>
<li>Setup your Redshift cluster (Follow these instructions <a href="//zappysys.com/blog/how-to-setup-amazon-redshift-cluster-for-outside-data-access/">to setup redshift cluster</a>)</li>
<li>Load some sample data to Redshift (Red more here: <a href="//zappysys.com/posts/sql-server-to-redshift-data-load-using-ssis/">How to load data to Redshift</a>)</li>
<li>Make sure you have correct connection settings to connect to Redshift cluster (Host name, Port, UserId, Password, DB name etc). You can get host name from AWS Console.</li>
<li>Make sure you have Access to S3 Bucket where files will be dumped from Redshift. You will need AccessKey and SecretKey to fetch files from S3</li>
</ol>
<h2>Step-1: Execute Redshift UNLOAD Command</h2>
<p>Very first step would be to unload redshift data as GZip file using <a href="//zappysys.com/products/ssis-powerpack/ssis-redshift-execute-sql-task/">ExecuteSQL Task for Amazon Redshift</a><br />
Below is SQL Command you can use to <em>extract data from Redshift</em>. Notice how we used variable placeholders in SQL Command. These placeholders are replaced at runtime with actual value stored in specified variable.</p><pre class="crayon-plain-tag">unload ('select * from (select * from customerdata limit 1000)')
to 's3://bw-rstest/stage/custdata'
credentials 'aws_access_key_id={{User::S3Accesskey}};aws_secret_access_key={{User::S3SecretKey}}'
ALLOWOVERWRITE</pre><p>
<b>Export as GZip files (Compressed files)</b></p>
<p>If you exporting data as compressed files to save data transfer cost then use GZIP option as below.</p>
<p><strong>NOTE:</strong> Make sure there are no spaces before and after AccessKey and SecretKey otherwise you may get error.</p><pre class="crayon-plain-tag">unload ('select * from (select * from customerdata limit 1000)')
to 's3://bw-rstest/stage/custdata_file_'
credentials 'aws_access_key_id={{User::S3Accesskey}};aws_secret_access_key={{User::S3SecretKey}}'
ALLOWOVERWRITE
GZIP</pre><p>
<h3>Common Errors / Troubleshooting</h3>
<p><strong>UNLOAD command issue with Region mismatch (S3 bucket vs Redshift Cluster)</strong></p>
<p>If your S3 bucket is in different region than Redshift cluster then above command may fail with &#8220;<em>301 permanent redirect error</em>&#8221; in that case you have to change your S3 bucket region. Region can be changed in AWS console (See S3 bucket properties and change location to match region with Redshift cluster region. Both regions must be same.</p>
<blockquote><p>ERROR: XX000: S3ServiceException:The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.,Status 301,Error PermanentRedirect</p></blockquote>
<p><strong>UNLOAD command issue with accesskey and secret key</strong></p>
<p>If you specify invalid accesskey or secretkey &#8211;or&#8211; you have misspelled keywords related to credentials &#8212; or &#8212; you have spaces before or after accesskey or secret key then you may get following error.</p>
<blockquote><p>ERROR: XX000: Invalid credentials. Must be of the format: credentials &#8216;aws_iam_role=&#8230;&#8217; or &#8216;aws_access_key_id=&#8230;;aws_secret_access_key=&#8230;[;token=&#8230;].</p></blockquote>
<h2>Step-2: Download data files from Amazon S3 Bucket to local machine</h2>
<p>Once files are exported to S3 bucket we can download then to local machine using <a href="//zappysys.com/products/ssis-powerpack/ssis-amazon-s3-task/">Amazon S3 Storage Task</a></p>
<h2>Step-3: Un-compress downloaded files</h2>
<p>If you have exported Redshift data as compressed files (using GZIP option) then you can use <a href="https://zappysys.com/products/ssis-powerpack/ssis-zip-file-task/" target="_blank">ZappySys Zip File task</a> to un-compress multiple files.</p>
<p>Or you can write Script to un-compress those files (see below code). You can skip this step if files are not compressed (not used GZIP option in command).</p>
<p>Here is sample <strong>C# code</strong> to un-compress <strong>GZip</strong> files</p><pre class="crayon-plain-tag">public void Main()
{
	System.IO.DirectoryInfo directorySelected = new System.IO.DirectoryInfo(@"C:\amazon\archive");

	foreach (System.IO.FileInfo fileToDecompress in directorySelected.GetFiles("custdata*_part_*"))
	{
		Decompress(fileToDecompress);
	}

	Dts.TaskResult = (int)ScriptResults.Success;
}
private static void Decompress(System.IO.FileInfo fileToDecompress)
{
	using (System.IO.FileStream originalFileStream = fileToDecompress.OpenRead())
	{
		string currentFileName = fileToDecompress.FullName;
		string newFileName = currentFileName.Remove(currentFileName.Length - fileToDecompress.Extension.Length);

		using (System.IO.FileStream decompressedFileStream = System.IO.File.Create(newFileName))
		{
			using (System.IO.Compression.GZipStream decompressionStream = new System.IO.Compression.GZipStream(originalFileStream, System.IO.Compression.CompressionMode.Decompress))
			{
				decompressionStream.CopyTo(decompressedFileStream);
				//Console.WriteLine("Decompressed: {0}", fileToDecompress.Name);
			}
		}
	}
}</pre><p>
&nbsp;</p>
<h2>Step-4: Loop through files using ForEachLoop Container</h2>
<p>Once files downloaded from S3 bucket we can now loop through files using SSIS ForEach Loop Task and load into SQL Server (One file in each iteration)</p>
<div id="attachment_165" style="width: 705px" class="wp-caption alignnone"><a href="//zappysys.com/blog/wp-content/uploads/2015/10/ssis-loop-amazon-s3-files.png"><img decoding="async" aria-describedby="caption-attachment-165" class="size-full wp-image-165" src="//zappysys.com/blog/wp-content/uploads/2015/10/ssis-loop-amazon-s3-files.png" alt="Loop through files downloaded from Amazon S3 (Exported using Redshift UNLOAD Command)" width="695" height="384" srcset="https://zappysys.com/blog/wp-content/uploads/2015/10/ssis-loop-amazon-s3-files.png 695w, https://zappysys.com/blog/wp-content/uploads/2015/10/ssis-loop-amazon-s3-files-300x166.png 300w" sizes="(max-width: 695px) 100vw, 695px" /></a><p id="caption-attachment-165" class="wp-caption-text">Loop through files downloaded from Amazon S3 (Exported using Redshift UNLOAD Command)</p></div>
<h2>Step-5: Data Flow &#8211; Load Redshift Data Files to SQL Server</h2>
<p>Inside data flow you can use Flat File source and OLEDB Destination for SQL Server. Just map correct File columns to SQL Server fields and you should be good. If needed convert Unicode/Non-unicode columns using Data Conversion Transform (This is not needed if source is DT_STR and target also DT_STR.. or source is DT_WSTR and target is DT_WSTR i.e. Unicode).</p>
<h2>Downloads</h2>
<p>To download above SSIS Package click on the below links. In order to test below package you first have to <a href="//zappysys.com/products/ssis-powerpack/">download SSIS PowerPack</a><br />
<a href="//zappysys.com/blog/wp-content/uploads/2015/11/RedshiftExtractDemo_2008.zip">Download Demo SSIS Package &#8211; SSIS 2008</a><br />
<a href="//zappysys.com/blog/wp-content/uploads/2015/11/RedshiftExtractDemo_2012.zip">Download Demo SSIS Package &#8211; SSIS 2012/2014</a></p>
<h2>Conclusion</h2>
<p>amazon Redshift is great way to start your data warehouse projects with very minimum investment in a very simple pay as you go model but loading or unloading data from redshift can be challenging task. Using <a href="//zappysys.com/products/ssis-powerpack/">SSIS PowerPack</a> you can perform Redshift data load or unload in few clicks.</p>
<p>The post <a href="https://zappysys.com/blog/extract-unload-redshift-data-sql-server-using-ssis/">Extract / Unload Redshift data into SQL Server using SSIS</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
