Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: Batch file to copy files from C drive to USB


29 Jul 2013   #1
tys

Windows 7 Professional x64
 
 
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 System SpecsSystem Spec
.

29 Jul 2013   #2

Microsoft Community Contributor Award Recipient

Windows 7 Home Premium x86 Service Pack 1 - Linux Mint Mate 14 x64
 
 

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 System SpecsSystem Spec
30 Jul 2013   #3
tys

Windows 7 Professional x64
 
 

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 System SpecsSystem Spec
.


30 Jul 2013   #4

Windows 7 Pro x64 SP1
 
 

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

Rich
My System SpecsSystem Spec
30 Jul 2013   #5

Microsoft Community Contributor Award Recipient

Windows 7 Home Premium x86 Service Pack 1 - Linux Mint Mate 14 x64
 
 

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 System SpecsSystem Spec
31 Jul 2013   #6
tys

Windows 7 Professional x64
 
 

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 System SpecsSystem Spec
31 Jul 2013   #7

Windows 7 Pro x64 SP1
 
 

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 System SpecsSystem Spec
01 Aug 2013   #8
tys

Windows 7 Professional x64
 
 

Sorry, I don't understand. Is this a new batch file? Or is this an add on to the existing batch file..?
My System SpecsSystem Spec
01 Aug 2013   #9

Microsoft Community Contributor Award Recipient

Windows 7 Home Premium x86 Service Pack 1 - Linux Mint Mate 14 x64
 
 

Quote   Quote: Originally Posted by tys View Post
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 System SpecsSystem Spec
01 Aug 2013   #10

Microsoft Community Contributor Award Recipient

Windows 7 Home Premium x86 Service Pack 1 - Linux Mint Mate 14 x64
 
 

You could remove the overwrite protection switches, I added those, to ensure you wanted to overwrite that file.
My System SpecsSystem Spec
Reply

 Batch file to copy files from C drive to USB




Thread Tools



Similar help and support threads for2: Batch file to copy files from C drive to USB
Thread Forum
Windows7 Batch File Copy Possible? Performance & Maintenance
How to copy a file from 1 pc to another pc in network using batch file General Discussion
search multiple files, copy+paste to new folder (batch file software?) General Discussion
Solved Creating Batch File with Robo Copy General Discussion
Solved a simple batch file for copy files and folders General Discussion
Batch file or Exe to copy & rename directory and update files General Discussion
batch file to copy from virtual machine to USB Virtualization

Our Sites

Site Links

About Us

Find 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 11:24 AM.
Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App
  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33