Solved

Copy Backup Files

Posted on 2007-11-21
2
179 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 250 total points
Comment Utility
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 250 total points
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

When writing XML code a very difficult part is when we like to remove all the elements or attributes from the XML that have no data. I would like to share a set of recursive MSSQL stored procedures that I have made to remove those elements from …
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

771 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now