Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Winrar - Self-extracting file using command line

Author  Topic 

umertahir
Posting Yak Master

154 Posts

Posted - 2011-12-20 : 12:04:42
I am looking for a command line option which I can put in my bat file from SQL to have a database bak file(.bak) to be zipped in a self-extracting format.

The command I am working on, whihc is in my .bat file, is:

"C:\Program Files\WinRAR\WinRar.exe" a -r -sfx E:\LandcatchBackupForLNS\LandcatchBackupForLNS.exe LandcatchBackupForLNS.bak



The error I get is:

! Cannot open E:\LandcatchBackupForLNS\LandcatchBackupForLNS.exe
! The system cannot find the file specified.


I want to above process to happen in the background and also it should overwrite the existing file, if it already exists.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-20 : 12:15:56
i think you should be looking at command line option for winrar

http://www.respower.com/page_tutorial_unrar

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

umertahir
Posting Yak Master

154 Posts

Posted - 2011-12-20 : 12:28:02
quote:
Originally posted by visakh16

i think you should be looking at command line option for winrar

http://www.respower.com/page_tutorial_unrar

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/





I am looking that into the command line option but I want the correct syntax for command-line to have self-extracting (.exe) files zipped up.
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-12-20 : 16:35:18
Only thing I can think of is the E:\LandcatchBackupForLNS\ folder doesn't exist or is a mapped network drive. If it's a mapped drive, you have to use the UNC path if you're going to call it from xp_cmdshell (which I don't recommend) or a SQL Agent job step (operating system command type).

Also, use the Rar.exe program in batch files, not WinRAR.exe. WinRar.exe is a GUI tool, rar.exe is command-line only. GUI programs should not be called from batch files, especially from a SQL Server process.
Go to Top of Page

umertahir
Posting Yak Master

154 Posts

Posted - 2011-12-21 : 04:39:09
quote:
Originally posted by robvolk

Only thing I can think of is the E:\LandcatchBackupForLNS\ folder doesn't exist or is a mapped network drive. If it's a mapped drive, you have to use the UNC path if you're going to call it from xp_cmdshell (which I don't recommend) or a SQL Agent job step (operating system command type).

Also, use the Rar.exe program in batch files, not WinRAR.exe. WinRar.exe is a GUI tool, rar.exe is command-line only. GUI programs should not be called from batch files, especially from a SQL Server process.



I couldn't find much help on creating self-extracting file so I ended up doing .rar file:

"C:\Program Files\WinRAR\Rar.exe" a -df -ep E:\LandcatchBackupForLNS\LandcatchBackupForLNS E:\LandcatchBackupForLNS\LandcatchBackupForLNS.bak

where
a : Add files to archive
df: Delete files after archiving
ep: Exclude paths from names


I will not run it as xp_cmdshell.

I am creating a bat file content from T-SQL and then executing the bat file in a SQL job under Type: Operating system (CmdEXEC) option.
Go to Top of Page
   

- Advertisement -