SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


unzip files using DTS


unzip files using DTS

Author
Message
Sridhar-137443
Sridhar-137443
SSChasing Mays
SSChasing Mays (636 reputation)SSChasing Mays (636 reputation)SSChasing Mays (636 reputation)SSChasing Mays (636 reputation)SSChasing Mays (636 reputation)SSChasing Mays (636 reputation)SSChasing Mays (636 reputation)SSChasing Mays (636 reputation)

Group: General Forum Members
Points: 636 Visits: 203
Hi,

I need to create a DTS package which will first unzip the files and put into specific directory and then load the data. Please let me know if you have any idea how to create the dts package and which tools I need to use. The zip files have the extension .gz. like 20030410.csv.gz

Thanks,
Sridhar.
AJ Ahrens
AJ Ahrens
SSCrazy
SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)

Group: General Forum Members
Points: 2796 Visits: 9
You will need to have a registered unzip i.e. PKZIP, WinZip, etc... You will also need a command-line editor (separate piece for WinZip). You will then need to write VBScript to unzip, push the file around, etc... prior to continuing the DTS package



Good Hunting!

AJ Ahrens


webmaster@kritter.net
Micha Petrovic-156323
Micha Petrovic-156323
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
Points: 1 Visits: 1

Hi there,

there is a command line utility named gzip.exe and is very simple to use.

Micha


Aaron West
Aaron West
SSC-Enthusiastic
SSC-Enthusiastic (187 reputation)SSC-Enthusiastic (187 reputation)SSC-Enthusiastic (187 reputation)SSC-Enthusiastic (187 reputation)SSC-Enthusiastic (187 reputation)SSC-Enthusiastic (187 reputation)SSC-Enthusiastic (187 reputation)SSC-Enthusiastic (187 reputation)

Group: General Forum Members
Points: 187 Visits: 161

Why not just use Perl, DBI and DBD :: ODBC? I hate DTS.

use strict;
#use DBI;
#use DBI qw(:sql_types);
use Compress::Zlib;
open FH, "<file.gz";
binmode FH;
{ local $/ = undef; my $filetext = <FH>}
$filetext = Compress::Zlib::memGunzip( $filetext );
# now either parse your file and insert records
# using a statement handle (see perldoc DBI)
# or just write the file out and call bcp
open FH, ">file.txt";
print FH $filetext;
close FH;
print `bcp ...`;

Seriously, I'm sure you can get it to work in DTS. I bet there are some activeX controls for ZIP you could embed into a DTS script. In any case, a web search might find a solution, such as this use of the WScript.Shell object:

http://www.sqltalk.org/ftopic17451.html


alkrup-104967
alkrup-104967
Grasshopper
Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)

Group: General Forum Members
Points: 21 Visits: 546

Hi people

AJ Ahrens right and u can add to DTS - Execute Process Task without using VBScript...





swede
swede
SSC-Enthusiastic
SSC-Enthusiastic (159 reputation)SSC-Enthusiastic (159 reputation)SSC-Enthusiastic (159 reputation)SSC-Enthusiastic (159 reputation)SSC-Enthusiastic (159 reputation)SSC-Enthusiastic (159 reputation)SSC-Enthusiastic (159 reputation)SSC-Enthusiastic (159 reputation)

Group: General Forum Members
Points: 159 Visits: 62

its not necessary to write an vbscript or a peril program, just use the store procedure xp_cmdshell to execute your dos command





Roy Ashbrook
Roy Ashbrook
Valued Member
Valued Member (71 reputation)Valued Member (71 reputation)Valued Member (71 reputation)Valued Member (71 reputation)Valued Member (71 reputation)Valued Member (71 reputation)Valued Member (71 reputation)Valued Member (71 reputation)

Group: General Forum Members
Points: 71 Visits: 17

gzip is free.

exec master.dbo.xp_cmdshell 'gzip -d ... file'
exec master.dbo.xp_cmdshell 'bcp ... file'


sergioman
sergioman
SSC Rookie
SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)

Group: General Forum Members
Points: 38 Visits: 55

Hi hope this helps.

'**********************************************************************
' Visual Basic ActiveX Script
'************************************************************************

Function Main()
'
' Create needed FileSystemObject and setup the directories for the file locations.
'
Set objFSO = CreateObject("Scripting.FileSystemObject")
strLogFile = "\\servername\drive_letter$\directory\Logs\unzipdata.log"
strZipArchiveDir = "\\servername\drive_letter$\directory\data"
strDir = "\\servername\drive_letter$\directory"

'-----------------------------------------------------------------------------------------------------------
'check to see if log files exists, if not create it
'-----------------------------------------------------------------------------------------------------------
If not objFSO.FileExists(strLogFile) then
Set master = objfso.CreateTextFile(strLogFile)
master.WriteLine " ***********************************************************"
master.WriteLine " File Created @ " & now
master.WriteLine " In LAST File Exists Routine @ " & now
master.WriteLine " ***********************************************************"
master.WriteLine

Else
Set master = objFSO.OpenTextFile(strLogFile,8)
master.WriteLine
master.WriteLine " ***********************************************************"
master.WriteLine " File Opened @ " & now
master.WriteLine " In LAST File Exists Routine @ " & now
master.WriteLine " ***********************************************************"
master.WriteLine

End if


yr=year(date)
mo=month(date)
if mo<10 then
mo = "0"&cstr(mo)
end if
dy=day(date)
if dy < 10 then
dy = "0" & cstr(dy)
end if

'-----------------------------------------------------------------------------------------------------------
'Look to see if a file matches the backup db with todays date
'-----------------------------------------------------------------------------------------------------------
Set objFSOFolder = objfso.getfolder(strZipArchiveDir)
for each objFSOFile in objfsofolder.files
if ucase(right(objFSOFile.name,3)) = "BAK" then
strFileNameBase = trim(left(objFSOFile.Name, len(objFSOFile.name)-4))
if trim(left(strFileNameBase,len(strFileNameBase)-4)) = "main" then
'-----------------------------------------------------------------------------------------------------------
'delete a the bak file
'-----------------------------------------------------------------------------------------------------------
'msgbox objFSOFile.name
objfso.DeleteFile strZipArchiveDir &"\"& objFSOFile.name
strFileNameBase = "main_"&yr&mo&dy

master.WriteLine objFSOFile.name & " ***********************************************************"
master.WriteLine objFSOFile.name & " DETECTED AND DELETED @ " & now
master.WriteLine objFSOFile.name & " ***********************************************************"
exit for
end if
end if
next
Set fso = CreateObject("Scripting.FileSystemObject")
strFileNameBase = "main_"&yr&mo&dy


'----------------------------------------------------------------------------------------------------------
' check to see if the zip file exists for today
'----------------------------------------------------------------------------------------------------------
If fso.FileExists(strZipArchiveDir & "\" & strFileNameBase & ".zip") then

master.WriteLine strFileNameBase & " *************************************************************************"
master.WriteLine strFileNameBase & " .zip exists @" & now
master.WriteLine strFileNameBase & " ZIP FILE EXISTS - SUCCESS "
master.WriteLine strFileNameBase & " **************************************************************************"
master.WriteLine

'-----------------------------------------------------------------------------------------------------------
'unzip file of the backup file
'-----------------------------------------------------------------------------------------------------------
Set WshShell = CreateObject("WScript.Shell")
strzip = "wzunzip -o " & strZipArchiveDir & "\" & "main_" & yr&mo&dy & ".zip " & strZipArchiveDir &"\"

WshShell.Run strZip,,true
master.WriteLine strFileNameBase & " *************************************************************************************"
master.WriteLine strFileNameBase & " " & strzip &" was unziped in the zip archive Folder @" & now
master.WriteLine strFileNameBase & " *************************************************************************************"
Set WshShell = nothing
Else
master.WriteLine strFileNameBase & " **************************************************************************"
master.WriteLine strFileNameBase & " *********** ZIP FILE DOES NOT EXIST *****FAILURE******"
master.WriteLine strFileNameBase & " **************************************************************************"

Main = DTSTaskExecResult_Failure
End if

'-----------------------------------------------------------------------------------------------------------
'check to see if the file was successfully unzipped
'-----------------------------------------------------------------------------------------------------------
If fso.FileExists(strZipArchiveDir & "\" & strFileNameBase & ".bak") then

master.WriteLine strFileNameBase & " *********************************************************************************"
master.WriteLine strFileNameBase & " found unzipped file @" & now
master.WriteLine strFileNameBase & " BAK FILE EXISTS - SUCCESS D1 "
master.WriteLine strFileNameBase & " *********************************************************************************"
master.WriteLine
'-----------------------------------------------------------------------------------------------------------
'make a copy of the file then delete old bak file
'-----------------------------------------------------------------------------------------------------------

master.WriteLine strFileNameBase & " *********************************************************************************"
master.WriteLine strFileNameBase & " preparing to copy " & strFileNameBase & ".bak to main.bak "
master.WriteLine strFileNameBase & " *********************************************************************************"
master.WriteLine

Set WshShell = CreateObject("WScript.Shell")

'*********************************************************************************"

used a batch file to copy file into another folder.
'*********************************************************************************"

'fso.copyfile strZipArchiveDir &"\"& strFileNameBase & ".bak", strZipArchiveDir &"\"& "main.bak",true

strzip = strDir & "\copy_main.bat"
WshShell.Run strzip,,true

Set WshShell = nothing

master.WriteLine strFileNameBase & "*********************************************************************"
master.WriteLine strFileNameBase & " " &strFileNameBase & ".bak copied as main.bak @" & now
master.WriteLine strFileNameBase & "**********************************************************************"


master.WriteLine strFileNameBase & " *********************************************************************************"
master.WriteLine strFileNameBase & " preparing to delete " & strFileNameBase & ".bak "
master.WriteLine strFileNameBase & " *********************************************************************************"
master.WriteLine

fso.DeleteFile strZipArchiveDir &"\"& strFileNameBase & ".bak"

master.WriteLine strFileNameBase & "*********************************************************************"
master.WriteLine strFileNameBase & " " & strFileNameBase & ".bak deleted @" & now
master.WriteLine strFileNameBase & "**********************************************************************"


Main = DTSTaskExecResult_Success
Else
master.WriteLine "****************************************************************************************"
master.WriteLine strFileNameBase & " *********** BAK FILE DOES NOT EXIST *****FAILURE******"
Main = DTSTaskExecResult_Failure
master.WriteLine "****************************************************************************************"


End if

master.WriteLine "FILE CLOSED @" & now
master.WriteLine "**********************************************************************************************************************************************************************************"
master.WriteLine
master.WriteLine

master.close


set fso = nothing
set objfso = nothing
set master = nothing
set objfsoFolder = nothing

End Function





Scott Faso
Scott Faso
Forum Newbie
Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: General Forum Members
Points: 3 Visits: 4
Now that is a great example! Thanks, I am going to give this a try!
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search