February 19, 2007 at 2:44 pm
I'm trying to find a way to copy bak and trn files to another server aftera backup job is run. I keep having syntax error near \ message. This is what I've been playing around with:
xcopy \\HCLLPROD\D$\"Program Files"\"Microsoft SQL Server"\MSSQL\BACKUP\HCLL_Production_DB\*.* \\HCLLTEST\D$\HCLL\"PROD BACK"\*.* /d
Any ideas are greatly appreciated.
February 19, 2007 at 4:54 pm
Don't embed the quotes... put the quotes around each full path.
--Jeff Moden
Change is inevitable... Change for the better is not.
February 20, 2007 at 6:59 am
I tried like this but still have invalid drive specification:
exec xp_cmdshell N'xcopy "D:\Program Files\Microsoft SQL Server\MSSQL\BACKUP\HCLL_Production_DB\HCLL_Production_DB_db_200702182300.BAK" \\HCLLTEST\D$\HCLL\PRODBACKUP\HCLLProductionDBdb20070218.BAK'
If the syntax is ok, could this be a permission issue? The folder on the other server I'm trying to copy to (HCLLTEST) has D: as share drive and the D:\HCLL\PRODBACKUP\ file is able to share.
Thanks a lot.
February 20, 2007 at 7:06 am
Denise,
Try exec master.dbo.xp_cmdshell 'dir \\hclltest\d$\prodbackup\*.*' to see if you get any a listing of the files successfully.
~Steve
February 20, 2007 at 10:57 am
Thanks so much for the help so far. This command works when run in query analyser:
exec xp_cmdshell N'xcopy "D:\Program Files\Microsoft SQL Server\MSSQL\BACKUP\HCLL_Production_DB\HCLL_Production_DB_db_200702182300.BAK" \\hclltest\prod_backup'
Now I'm trying to use it in a scheduled job and it doesn't give an error and says it runs successfully, but it doesn't actually do anything.
I want to run these steps, so it will remove the previous bak file and copy over the new daily bak file:
exec xp_cmdshell "del \\HCLLTEST\prod_backup\*.bak
exec xp_cmdshell N'xcopy "D:\Program Files\Microsoft SQL Server\MSSQL\BACKUP\HCLL_Production_DB\HCLL_Production_DB_db_*.BAK" \\hclltest\prod_backup'
Again any help is greatly appreciated.
February 21, 2007 at 6:20 am
By default XCOPY will prompt to overwrite files and since prompts cannot be resolved in xp_cmdshell without using TYPE and redirector/pipe, I suspect that is why 'nothing happens'
Try adding /Y to XCOPY to suppress the prompt and overwrite, eg
exec xp_cmdshell N'xcopy /Y "D:\Program Files\Microsoft SQL Server\MSSQL\BACKUP\HCLL_Production_DB\HCLL_Production_DB_db_*.BAK" \\hclltest\prod_backup\'
also add an additional backslash to the destination if using the above syntax to tell XCOPY that the destination is a directory
Far away is close at hand in the images of elsewhere.
Anon.
February 21, 2007 at 7:02 am
I tried running the job as suggested
exec xp_cmdshell N'xcopy /Y "D:\Program Files\Microsoft SQL Server\MSSQL\BACKUP\HCLL_Production_DB\HCLL_Production_DB_db_*.BAK" \\hclltest\prod_backup\'
It ran successfully, but still didn't copy the file over to hclltest server, no error messages. If there is no error because the xp_cmdshell ran, is there a way to tell why it isn't copying?
Could it be access issues, I can copy when using query analyser, so is this some thing to do with sql agent running the job?
Thanks so much for your help!
February 21, 2007 at 10:41 am
Probably access permissions, 2 thing to try
1. Change job step to log information to a file and check the file
2. change the command to
exec xp_cmdshell N'xcopy /Y "D:\Program Files\Microsoft SQL Server\MSSQL\BACKUP\HCLL_Production_DB\HCLL_Production_DB_db_*.BAK" c:\job.txt'">\\hclltest\prod_backup\ > c:\job.txt'
and providing access to the c: drive is ok check the job.txt file
Far away is close at hand in the images of elsewhere.
Anon.
February 21, 2007 at 12:15 pm
I tried his and in the job.txt file is:
0 file(s) copied
Any other ideas?
February 22, 2007 at 5:02 am
Doh!! XCOPY errors are redirected to STDERR and wont appear in the job.txt file
Set the Job Step to log output and check the contents of that file
Far away is close at hand in the images of elsewhere.
Anon.
February 22, 2007 at 7:23 am
Well, I'm trying to teach myself all this, and it seems to take me forever!
I get for output: "Invalid drive specification {null}. The step succeeded."
when running:
exec xp_cmdshell N'xcopy /Y "D:\Program Files\Microsoft SQL Server\MSSQL\BACKUP\HCLL_Production_DB_db_200702202300.BAK" \\hcll\prod_backup\ >c:\job.txt'
Thanks again for the help.
February 22, 2007 at 7:31 am
ah!
Just spotted something, you have a space in the output directory, you will need to put quotes around that as well
exec xp_cmdshell N'xcopy /Y "D:\Program Files\Microsoft SQL Server\MSSQL\BACKUP\HCLL_Production_DB_db_200702202300.BAK" "\\hcll\prod_backup\"'
Far away is close at hand in the images of elsewhere.
Anon.
February 22, 2007 at 8:20 am
There is an underscore there, prod_backup. But I tried with quotes around as suggested and have same error. Thanks!
February 22, 2007 at 9:05 am
Only two things I can think of then
First, and most probable, your SQL Server is running under the 'Local System Account' instead of a Domain account. The Local System Account cannot access the network.
Second, either the server/pc hcll does not exist or the name cannot be resolved or the share prod_backup does not exist on that server/pc
Far away is close at hand in the images of elsewhere.
Anon.
February 22, 2007 at 10:17 am
SQL Server is running under the local system account. Do we need to change just the SQL Server Agent service to a domain acccount, or should w change the MSSQL Server service too? And thanks.
Viewing 15 posts - 1 through 15 (of 15 total)
You must be logged in to reply to this topic. Login to reply