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.

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • 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.

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • 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