sbagireddi
asked on
Copy Backup Files
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_200 71029_LOG_ flip2.TRN
C:\source\Archive\test_200 71029_LOG_ flip2.TRN
C:\source\Archive\test_200 71029_LOG_ flip2.TRN
C:\source\Archive\test_200 71029_LOG_ flip2.TRN
C:\source\Archive\test_200 71029_LOG_ flip2.TRN
C:\source\Archive\test_200 71029_LOG_ flip2.TRN
C:\source\Archive\test_200 71029_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
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_200
C:\source\Archive\test_200
C:\source\Archive\test_200
C:\source\Archive\test_200
C:\source\Archive\test_200
C:\source\Archive\test_200
C:\source\Archive\test_200
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.