Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Copy Backup Files

Posted on 2007-11-21
2
Medium Priority
?
243 Views
Last Modified: 2010-03-19
I have a script to copy backup files.

This is what is does:

--Make a new directory to hold last month's backup files
SET @cmd = 'mkdir C:\dest\Archive\' + CONVERT(char(6), DATEADD(month, DATEDIFF(month, 0, getdate()) -1, 0), 112)
EXEC master..xp_cmdshell @cmd, NO_OUTPUT

--Loop through the filenames in the temp table and copy them to the new directory
DECLARE @current_dir varchar(255)

DECLARE test_cursor CURSOR FOR
SELECT
current_dir
FROM #test_archive

      
OPEN test_cursor
FETCH test_cursor INTO
@current_dir

WHILE (@@FETCH_STATUS = 0)
BEGIN


     SET @cmd = 'copy' +  @log_current_dir + 'C:\test\PLFullArchive' + CONVERT(char(6), DATEADD(month, DATEDIFF(month, 0, getdate()) -1, 0), 112)
      EXEC master..xp_cmdshell @cmd, NO_OUTPUT

      FETCH test_cursor INTO
      @current_dir
END



CLOSE test_cursor
DEALLOCATE test_cursor


The # test_archive temp table contains :

current_dir
C:\source\Archive\test_20071029_LOG_flip2.TRN
C:\source\Archive\test_20071029_LOG_flip2.TRN
C:\source\Archive\test_20071029_LOG_flip2.TRN
C:\source\Archive\test_20071029_LOG_flip2.TRN
C:\source\Archive\test_20071029_LOG_flip2.TRN
C:\source\Archive\test_20071029_LOG_flip2.TRN
C:\source\Archive\test_20071029_LOG_flip2.TRN

For some reason the copy command does not copy the files to the destination.
Is there something I am missing here.
This is part of a larger stored procedure.
You can run the copy command seperately.

Thanks


0
Comment
Question by:sbagireddi
2 Comments
 
LVL 17

Accepted Solution

by:
Chris Mangus earned 1000 total points
ID: 20330529
Print the contents of the @cmd variable and examine it.  I don't think you have spaces where you need them.

i.e. - your output command probably reads:

copyc:\mylogdirC:\test\PLFullArchive...etc

Try:

SET @cmd = 'copy ' +  @log_current_dir + ' C:\test\PLFullArchive' + CONVERT(char(6), DATEADD(month, DATEDIFF(month, 0, getdate()) -1, 0), 112)
0
 
LVL 18

Assisted Solution

by:Yveau
Yveau earned 1000 total points
ID: 20330572
Run the xp_cmdshell statement without the NO_OUTPUT and you will see what the error is.

My guess is:
'copy' +  @log_current_dir + 'C:\test\PLFullArchive' + CONVERT(char(6), DATEADD(month, DATEDIFF(month, 0, getdate()) -1, 0)

will end up like:
copyC:\source\Archive\test_20071029_LOG_flip2.TRNC:\test\PLFullArchive200710

and you mean to have something like:
copy C:\source\Archive\test_20071029_LOG_flip2.TRN C:\dest\Archive\200710

so you are looking for:
SET @cmd = 'copy ' +  @log_current_dir + ' C:\dest\Archive' + CONVERT(char(6), DATEADD(month, DATEDIFF(month, 0, getdate()) -1, 0), 112)

Hope this helps ...
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are some very powerful Dynamic Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a di…
So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question