xp_cmdshell

  • Hi All

    How would I setup a script to copy files from a shared location on one server, to a shared location on another server?

    The extension of the files would be .trn

    I assume that I would need to use xp_cmdshell

    Thanks

  • SQLSACT (7/17/2012)


    Hi All

    How would I setup a script to copy files from a shared location on one server, to a shared location on another server?

    The extension of the files would be .trn

    I assume that I would need to use xp_cmdshell

    Thanks

    No, you could use a VBscript or even a powershell script and run as a sql server agent job step, no XP_CMDSHELL needed here

    -----------------------------------------------------------------------------------------------------------

    "Ya can't make an omelette without breaking just a few eggs" 😉

  • SQLSACT (7/17/2012)


    Hi All

    How would I setup a script to copy files from a shared location on one server, to a shared location on another server?

    The extension of the files would be .trn

    I assume that I would need to use xp_cmdshell

    Thanks

    You could use the xp_cmdshell for this with a command that looks a little like this:

    EXEC xp_cmdshell 'copy *.trn WHEREEVER/trn_backups';

    The xp_cmdshell is not the best choice for something like this though.

    The way to go is to:

    1) Create a new SQL Server job (say named, "copy transaction log files")

    2) Add a step with type Operating System (cmdExec)

    3) Add this to the command area:

    copy *.trn WHEREEVER/trn_backups'

    4) Schedule the job to run whenever you wish

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • I would use a Powershell Script for this. Flexible and easy to change, if required.

    If you need help with it let us know.

  • OTF (7/17/2012)


    I would use a Powershell Script for this. Flexible and easy to change, if required.

    If you need help with it let us know.

    Thanks

    I definately need help with this

    Is it possible to only copy files that don't already exist in the destination?

    Thanks

  • SQLSACT (7/17/2012)


    OTF (7/17/2012)


    I would use a Powershell Script for this. Flexible and easy to change, if required.

    If you need help with it let us know.

    Thanks

    I definately need help with this

    Is it possible to only copy files that don't already exist in the destination?

    Thanks

    That should be possible, yes.

  • SQLSACT (7/17/2012)


    Hi All

    How would I setup a script to copy files from a shared location on one server, to a shared location on another server?

    The extension of the files would be .trn

    I assume that I would need to use xp_cmdshell

    Thanks

    I just actually went through and set up CMDEXEC sql agent jobs to get rid of xp_cmdshell. as part of my effort to boost security any thing that uses xp_cmdshell has to be rewritten so i can eventually disable it on our servers. i found it opens a hole that does not need to exist any more.


    For faster help in answering any problems Please read How to post data/code on a forum to get the best help - Jeff Moden[/url] for the best way to ask your question.

    For performance Issues see how we like them posted here: How to Post Performance Problems - Gail Shaw[/url]

    Need to Split some strings? Jeff Moden's DelimitedSplit8K[/url]
    Jeff Moden's Cross tab and Pivots Part 1[/url]
    Jeff Moden's Cross tab and Pivots Part 2[/url]

  • capn.hector (7/17/2012)


    i found it opens a hole that does not need to exist any more.

    It only opens a hole if you're server security isn't setup correctly. xp_CmdShell isn't the problem.... bad security is.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

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

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