Batch file to copy files from C drive to USB

Page 1 of 2 12 LastLast

  1. tys
    Posts : 38
    Windows 7 Professional x64
       #1

    Batch file to copy files from C drive to USB


    Hi all,

    To increase our backup solutions, we have decided to backup our SQL database every hour to a folder within the C drive (we couldn't get it to backup straight to a USB drive). So now we need a way (batch file best solution?) to copy these files to the USB drive, lets say every 1.05hours just after they've been created?

    Maybe we could copy the entire folder every hour and delete old backups that are in this folder and to the new place for the backups. (although I guess it won't work as it'll have the same folder name once it has been copied).

    Or copy the individual files to that new folder although with this they have all different names so is it possible to copy the newest file to the new folder and then after this delete the old backups from a certain time frame?

    Big thanks for your help!
      My Computer

  2.    #2

    Code:
    REM Creates a Backup of files every hour
    @echo off
    :start
    XCOPY <source path> <destination path> /w /f /-y
    TIMEOUT /t 3600 /nobreak
    goto start
    This might work, I'm no expert by any means, but the batch file should copy all the files, and then pause for a hour, and then loop back to the start and complete the same process again.

    Here's what the XCOPY switches mean - http://www.microsoft.com/resources/d....mspx?mfr=true
      My Computer


  3. tys
    Posts : 38
    Windows 7 Professional x64
    Thread Starter
       #3

    Doesn't seem to have worked. just brings up the black command prompt and goes again.

    I'm a novice with scripting... the destination path has been listed as "B:\" as I've mapped a USB drive from the physical server to the virtual server. I'm not sure if that''s the correct path?

    Regards,
      My Computer


  4. Posts : 1,800
    Windows 7 Pro x64 SP1
       #4

    Tys, you did put quotes around the source and target for the xcopy????

    Rich
      My Computer

  5.    #5

    Thanks Rich, here's the modification, with an example of my Test file I used to make sure the Batch file works, and it does work now:

    Code:
    @echo off
    :start
    XCOPY "C:\Users\Harry\Documents\Test.txt" "C:\Users\Harry\Documents\Batch Tutorials" /w /f /-y
    TIMEOUT /t 3600 /nobreak
    goto start
      My Computer


  6. tys
    Posts : 38
    Windows 7 Professional x64
    Thread Starter
       #6

    Hello. This does work, although when the time period runs out I have to manually click any button and then select "Yes or No". I want it to do this manually...

    Thanks!
      My Computer


  7. Posts : 1,800
    Windows 7 Pro x64 SP1
       #7

    Tys, Piping works fine.
    TIMEOUT /t 3600 /nobreak <yes.txt

    this then pipes the yes.txt file to the question Yes or No.
    create the yes.txt file with the word YES and a Carriage Return.
    should do it, you might have to experiment with the YES and Y

    Rich
      My Computer


  8. tys
    Posts : 38
    Windows 7 Professional x64
    Thread Starter
       #8

    Sorry, I don't understand. Is this a new batch file? Or is this an add on to the existing batch file..?
      My Computer

  9.    #9

    tys said:
    Hello. This does work, although when the time period runs out I have to manually click any button and then select "Yes or No". I want it to do this manually...

    Thanks!
    Don't you mean you want to do it automatically?
      My Computer

  10.    #10

    You could remove the overwrite protection switches, I added those, to ensure you wanted to overwrite that file.
      My Computer


 
Page 1 of 2 12 LastLast

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 06:13.
Find Us