SQL Copy only newest files

  • Hi All,

    I have a question that i hope SQL can do because I can't find anything on the net at all. I know this may not be best method but this is the only way i can do this as im using SQL express running nightly backup jobs then copying it remotely onto another site.

    My entire script has been completed bar this 1 issue. I'll ask the question first and if not possible might need help on best method for this to work

    When using the below statement I'm currently copying everything from "C:\Backup" with the extension of .BAK to my new secondary target folder "\\testmachine1\backup".

    EXEC master.dbo.xp_cmdshell 'copy c:\backup\*.BAK \\testmachine1\backup\', NO_OUTPUT

    What i don't like about this is that I'm copying everyfile that is .BAK and I'm over-writing all files from \\testmachine\backup. Therefore im transferring over 5GB of files (about 10 days worth of .bak)All my files that are .bak are generated with a new name. All i want to do is copy the newest file across (500MB / 1 day) but i can't seem to get this working? Any ideas as i believe you can't add any variables to the statement

    Thanks

    Tava

  • Ignore my question, I didnt quiet understand what a cmdshell could actually achieve. Used the Robocopy /MIR option to get the results i wanted...

    Thanks Tava

Viewing 2 posts - 1 through 1 (of 1 total)

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