unzip file from t sql cmd line

  • Hi I am getting incorrect command line error when I type this code,

    DECLARE @Result int

    DECLARE @cmd varchar(200)

    set @cmd = '"\\localhost\7-Zip\7z.exe" C:\test\servername_dbzip_testdb-20160712.zip c:\test\dumps'

    print @cmd

    EXEC @Result = xp_cmdshell @cmd

  • What error are you getting?

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • Is your server really called 'localhost'? I know that works for default SQL Server instances, but I'm not sure about UNC paths.

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • Here is the error message:-

    NULL

    7-Zip [64] 9.20 Copyright (c) 1999-2010 Igor Pavlov 2010-11-18

    NULL

    NULL

    Error:

    Incorrect command line

    NULL

  • yeah when I type \\localhost in windows explorer and because I have shared 7-zip folder, I can browse this path and its my local machine where I am admin

  • Have you tried running the command in the command-prompt directly? As opposed to through xp_cmdshell, I mean.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • You have not included 'e' (Extract). See info here.

    Gus is right: make it work natively first, then plug into T-SQL.

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • Thanks Phil and GsSquad it worked, When I added some switches.

    set @cmd = '\\localhost\7-Zip\7z e C:\test\servername_dbzip_testdb-20160712.zip -oc:\test\dumps *.bak -y'

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply