copy file

  • Hi All

    Please help to solve this issue.

    I want to copy backup file from one machine to another,i want to achieve this by using sql query i tried xp_cmdshell copy command but am getting access denied.I created a windows login in both machines and same sql login in the server.

    Thanks in Advance

  • if you want to use xp_cmdshell, you'll have to open it at sqlserver instance level ! (which I do not advise !)

    We use a SQLAgent job to perform the backups.

    The last step in these jobs is an xcopy to the safe zone.

    e.g.

    execute @ReturnCode = msdb.dbo.sp_add_jobstep @job_id = @JobID ,

    @step_id = 9, @cmdexec_success_code = 0, @on_success_action = 1,

    @on_success_step_id = 0, @on_fail_action = 2, @on_fail_step_id = 0,

    @retry_attempts = 0, @retry_interval = 1, @os_run_priority = 0, @flags = 0,

    @step_name = N'CopyToBackupSrv', @subsystem = N'CmdExec',

    @command = N'XCOPY C:\MSSQL\BACKUP\*.* \\mysafezoneserver\bu2tapeDay$\sqlserverisntancename\Database\ /c /k /h /v /y'

    The SQLAgent service account has been given auth to write to this directory and

    it has the authority to use the cmdexe subsystem. (jobowner = 'sa')

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

  • The machine to which i have to take backup is not in the same domain nor it have any domain.When i connect to that machine from the RUN am able to access that.

  • You could off course include a

    NET USE ... user:yyy pasword:yyy

    don't forget to clean up after teh copy !

    NET HELP USE provides more info

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

  • Can you please explain a bit more on that.

  • Excuse me for the very late response :blush:

    Kind of lost track of this thread.

    This drive mapping should loke something like this

    NET USE * \\TheOtherServer\TheSharename Password /USER:Thedomainname\TheOtherusername /PERSISTENT:NO

    xcopy c:\myfile.txt \\TheOtherServer\TheSharename

    NET USE * \\TheOtherServer\TheSharename /DELETE

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

Viewing 6 posts - 1 through 5 (of 5 total)

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