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
x BlueRobot

 

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
richnrockville

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
x BlueRobot

 

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
richnrockville

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
x BlueRobot

 

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
x BlueRobot

 

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
Thread Forum
Windows7 Batch File Copy Possible?
Fellow Forum Members, I have two external hard drives I'm calling Hard Drive A and Hard Drive B. Hard Drive A & B are mounted to external USB cradles. Both USB cradles are connected to the same PC containing Hard Drive C. My objective is to transfer all data files, folders, sub folders from both...
Performance & Maintenance
How to copy a file from 1 pc to another pc in network using batch file
Help me make a batch file that copies a file from one computer to another computer in a network... PC1 = Source PC2 = Destination I want to copy a file from PC1's Drive E: to PC2's Drive E:
General Discussion
search multiple files, copy+paste to new folder (batch file software?)
I am a complete newbie when it comes to batch files and batch file software, so apologies in advance. I've done some research on Google etc but I seem to just be getting more and more confused trying to use various different scripts and programs and reading different info on various websites. ...
General Discussion
a simple batch file for copy files and folders
I want to write a batch file that do this for me: - makes a directory with the "yy.mm.dd.hh.mm" as the directory name, - copies files and folders from a TEST directory to above destination, - copies only new (or modified) files from the TEST directory to a separate folder. Any Idea?
General Discussion
Batch file or Exe to copy & rename directory and update files
I require a batch file or free utility that i can redistribute from my web site to other users, (gamers) that will copy the contents of a directory inside their game to a new location and re-name the directory at the same time. Something like this; Copy "Genesis\Vehicles\truck\diesel\4tonbaker"...
General Discussion
batch file to copy from virtual machine to USB
If C:\ is the root of the virtual machine and U:\ is the USB stick, I can PERFORM "copy C:\folder\** U:\folder", but that line in a batch file does not work. How can I fix that ?
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 14:25.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App