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
Imprinted Gifts
Server Racks
Shop Online
Auto Insurance Quote
Car Donations
Laptop Batteries
PDA Phones & Cases
Memory
Web Design
Promotional Products
Web Hosting Directory
Career Education
Build a Server Rack
Promote Your Website




MySpace Joins eBay, Yahoo in Open Profile Push

News Corp. Unit Under Fire for Ties to Hacker

Are Non-PC Devices Hurting 'Net Innovation?

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. »
Related Articles
Compress SQL Server backups using WinZip – Part I

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

Justtechjobs.com Post A Job | Post A Resume
MS SQL
October 26, 2005
Compress SQL Server backups using WinZip – Part II
By Muthusamy Anantha Kumar aka The MAK

Part I of this article illustrated how to use reasonably priced WinZip to do a full backup and transaction log backup. Part II of this article is going to illustrate how to delete the original backup file after zipping the backup file using WinZip and how to uncompress the compressed backup files using the WinZip command line wzunzip.exe.

Step 1

Create the following procedure on the server. Download USP_BAKZIP2.SQL.

SET QUOTED_IDENTIFIER OFF
GO
USE MASTER
GO
IF EXISTS (SELECT * FROM DBO.SYSOBJECTS 
 WHERE ID = OBJECT_ID(N'[DBO].[USP_BAKZIP2]') 
 AND OBJECTPROPERTY(ID, N'ISPROCEDURE') = 1)
DROP PROCEDURE [DBO].[USP_BAKZIP2]
GO
CREATE PROCEDURE USP_BAKZIP2
@DBNAME VARCHAR(256),
@BAKPATH VARCHAR(1000),
@ZIPPATH VARCHAR(1000),
@TYPE VARCHAR(1), 
 -- F (FULL BACKUP) T (TRANSACTION LOG BACKUP)
@DELETEFLAG BIT =1
AS
--CREATED BY : MAK
--CREATED DATE : OCT 12, 2005
--OBJECTIVE: TO BACKUP THE DATABASE OR TRANSACTIONAL 
 LOG BACKUP AND ZIP IT USING WINZIP
DECLARE @SQLSTATEMENT VARCHAR(2000)
SET @SQLSTATEMENT =''
DECLARE @BTYPE VARCHAR(25)
DECLARE @BTYPEEXT VARCHAR(4)
DECLARE @TIMESTAM VARCHAR(20)
SET @TIMESTAM=REPLACE(REPLACE(REPLACE
 (CONVERT(VARCHAR(25),
 GETDATE(),120),'-','_'),':','_'),' ','_')
IF @TYPE ='F' 
BEGIN
SET @BTYPE =' DATABASE '
SET @BTYPEEXT='.BAK'
END
IF @TYPE ='T' 
BEGIN
SET @BTYPE =' LOG '
SET @BTYPEEXT='.TRN'
END
IF @TYPE NOT IN ('T','F') 
BEGIN
GOTO ERROR
END

SET @SQLSTATEMENT = 'BACKUP ' + @BTYPE + @DBNAME+' TO DISK ="'+@BAKPATH+@DBNAME+'_'+@TIMESTAM+@BTYPEEXT+'" '
PRINT 'SQL STATEMENT'
PRINT '-------------'
PRINT @SQLSTATEMENT 
PRINT 'MESSAGE'
PRINT '-------'
EXEC (@SQLSTATEMENT)
SET @SQLSTATEMENT = 'C:\ZIP.BAT "'+@ZIPPATH+@DBNAME+'_'+@TIMESTAM+@BTYPEEXT+'.ZIP" 
  "'+@BAKPATH+@DBNAME+'_'+@TIMESTAM+@BTYPEEXT+'"'
PRINT 'SQL STATEMENT'
PRINT '-------------'
PRINT @SQLSTATEMENT 
PRINT 'MESSAGE'
PRINT '-------'
EXEC MASTER..XP_CMDSHELL @SQLSTATEMENT 
IF @DELETEFLAG=1 
BEGIN
SET @SQLSTATEMENT = ' DEL '+@BAKPATH+@DBNAME+'_'+@TIMESTAM+@BTYPEEXT
PRINT 'SQL STATEMENT'
PRINT '-------------'
PRINT @SQLSTATEMENT 
PRINT 'MESSAGE'
PRINT '-------'
EXEC MASTER..XP_CMDSHELL @SQLSTATEMENT 
END
GOTO FINAL

ERROR:
PRINT 'SYNTAX : EXEC USP_BAKZIP2 "DATABASENAME","BAKPATH","ZIPPATH","TYPE",DELETEFLAG'
PRINT '"TYPE" SHOULD EITHER BE "F" FOR FULL BACKUP OR "T" FOR TRANSACTIONAL LOG BACKUP'
PRINT 'DELETEFLAG SHOULD EITHER BE 1 FOR DELETING THE BACKUP OR 0 FOR NOT TO DELETE THE BACKUP'
PRINT 'EXAMPLE: EXEC USP_BAKZIP2 "MASTER","D:\SQLDUMPS\","D:\SQLDUMPS\","F",1'
GOTO FINAL
FINAL:

GO

Step 2

Let us execute the stored procedure as shown below.

EXEC USP_BAKZIP2 "MASTER","D:\SQLDUMPS\","D:\SQLDUMPS\","F",1

This statement does a full database backup and zips the backup file to the location D:\SQLDumps. It then deletes the backup file that was created.

If the deleteflag =0, then the procedure will not delete the backup that was created.

Once the procedure is executed, the database is backed up and zipped with the following message.

SQL STATEMENT
-------------
BACKUP  DATABASE MASTER TO DISK ="D:\SQLDUMPS\MASTER_2005_10_18_14_55_51.BAK" 
MESSAGE
-------
Processed 1848 pages for database 'MASTER', file 'master' on file 1.
Processed 1 pages for database 'MASTER', file 'mastlog' on file 1.
BACKUP DATABASE successfully processed 1849 pages in 0.341 seconds (44.398 MB/sec).
SQL STATEMENT
-------------
C:\ZIP.BAT "D:\SQLDUMPS\MASTER_2005_10_18_14_55_51.BAK.ZIP" "D:\SQLDUMPS\MASTER_2005_10_18_14_55_51.BAK"
MESSAGE
-------
output
C:\WINDOWS\system32>"C:\PROGRAM FILES\WINZIP\WZZIP.EXE" -ee -ybc 
 "D:\SQLDUMPS\MASTER_2005_10_18_14_55_51.BAK.ZIP" 
 "D:\SQLDUMPS\MASTER_2005_10_18_14_55_51.BAK" 
WinZip(R) Command Line Support Add-On Version 1.1 SR-1 (Build 6224)
Copyright (c) WinZip Computing, Inc. 1991-2004 - All Rights Reserved
Searching...                                    ...         ..      
  Adding MASTER_2005_10_18_14_55_51.BAK...............................                                .......... 
.....................                                                                                             .   
creating Zip file D:\SQLDUMPS\MASTER_2005_10_18_14_55_51.BAK.ZIP

(15 row(s) affected)
SQL STATEMENT
-------------
 DEL D:\SQLDUMPS\MASTER_2005_10_18_14_55_51.BAK
MESSAGE
-------
output

(1 row(s) affected)

Let us execute the stored procedure as shown below.

EXEC USP_BAKZIP2 "Northwind","D:\SQLDUMPS\","D:\","T",1

This statement does a transaction log backup and zips the backup file to the location D:\. In addition, it deletes the transaction log file that is created.

Once the procedure is executed, the database transaction log is backed up and zipped with the following message.

SQL STATEMENT
-------------
BACKUP  LOG Northwind TO DISK ="D:\SQLDUMPS\Northwind_2005_10_18_14_59_08.TRN" 
MESSAGE
-------
BACKUP LOG successfully processed 0 pages in 0.007 seconds (0.000 MB/sec).
SQL STATEMENT
-------------
C:\ZIP.BAT "D:\Northwind_2005_10_18_14_59_08.TRN.ZIP" "D:\SQLDUMPS\Northwind_2005_10_18_14_59_08.TRN"
MESSAGE
-------
output
C:\WINDOWS\system32>"C:\PROGRAM FILES\WINZIP\WZZIP.EXE" -ee -ybc 
 "D:\Northwind_2005_10_18_14_59_08.TRN.ZIP" 
 "D:\SQLDUMPS\Northwind_2005_10_18_14_59_08.TRN" 
WinZip(R) Command Line Support Add-On Version 1.1 SR-1 (Build 6224)
Copyright (c) WinZip Computing, Inc. 1991-2004 - All Rights Reserved
Searching...                                    ...         ..      
  Adding Northwind_2005_10_18_14_59_08.TRN...         .   
creating Zip file D:\Northwind_2005_10_18_14_59_08.TRN.ZIP

(8 row(s) affected)
SQL STATEMENT
-------------
 DEL D:\SQLDUMPS\Northwind_2005_10_18_14_59_08.TRN
MESSAGE
-------
output

(1 row(s) affected)

Now let us see how we can uncompress the compressed backup file using a stored procedure and WinZip.

Step 1

Create C:\unzip.bat on the SQL Server box as shown below. [Refer Fig 1.0]

"C:\PROGRAM FILES\WINZIP\wzunzip.exe" -ybc %1 %2


Fig 1.0

Step 2

Create the following procedure on the server. Download USP_UNZIP.SQL.

SET QUOTED_IDENTIFIER OFF
GO
USE MASTER
GO
IF EXISTS (SELECT * FROM DBO.SYSOBJECTS 
 WHERE ID = OBJECT_ID(N'[DBO].[USP_UNZIP]') 
 AND OBJECTPROPERTY(ID, N'ISPROCEDURE') = 1)
DROP PROCEDURE [DBO].[USP_UNZIP]
GO
CREATE PROCEDURE USP_UNZIP
@ZIPFILE VARCHAR(2000),
@BAKPATH VARCHAR(1000)
AS
--CREATED BY : MAK
--CREATED DATE : OCT 12, 2005
--OBJECTIVE: UNZIP THE GIVE ZIPPED FILE TO A FOLDER
--SYNTAX: USP_UNZIP "D:\Northwind_2005_10_18_14_59_08.TRN.ZIP","D:\"
DECLARE @SQLSTATEMENT VARCHAR(2000)
SET @SQLSTATEMENT =''
SET @SQLSTATEMENT = 'C:\UNZIP.BAT "'+@ZIPFILE+'" "'+@BAKPATH+'"'
PRINT 'SQL STATEMENT'
PRINT '-------------'
PRINT @SQLSTATEMENT 
PRINT 'MESSAGE'
PRINT '-------'
EXEC MASTER..XP_CMDSHELL @SQLSTATEMENT 
GO

Let us execute the stored procedure as shown below.

USP_UNZIP "D:\Northwind_2005_10_18_14_59_08.TRN.ZIP","D:\"

This statement un-compresses the backup file to the destination folder with the following message.

SQL STATEMENT
-------------
C:\UNZIP.BAT "D:\Northwind_2005_10_18_14_59_08.TRN.ZIP" "D:\"
MESSAGE
-------
output
C:\WINDOWS\system32>"C:\PROGRAM FILES\WINZIP\wzunzip.exe" -ybc "D:\Northwind_2005_10_18_14_59_08.TRN.ZIP" "D:\" 
WinZip(R) Command Line Support Add-On Version 1.1 SR-1 (Build 6224)
Copyright (c) WinZip Computing, Inc. 1991-2004 - All Rights Reserved
Zip file: D:\Northwind_2005_10_18_14_59_08.TRN.ZIP
Searching...                                    
unzipping D:\Northwind_2005_10_18_14_59_08.TRN.   

(9 row(s) affected)

Conclusion

This article has illustrated how to delete the original backup file after zipping the backup files using WinZip. It also illustrated how to uncompress the compressed backup files using the WinZip command line wzunzip.exe.

» See All Articles by Columnist MAK

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

IT in 2018: Download Free eBook By The Author Of "Does IT Matter?" Simple Registration Is Required.
Five Trends for Application Development & Program Management. Download Complimentary Report Now.
Flash Demo: Learn how IBM Information Server Blade is easy to manage, highly scalable and efficient.
Learn about expanding business opportunities for the reseller channel. Visit IT Channel Planet.
Webcast: Five Virtualization Trends to Watch. Produced for HP, Citrix, and Intel.


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
Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES