Batch file to copy files from C drive to USB

tys

New member
Member
Local time
2:18 PM
Messages
38
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 My Computer

At a glance

Windows 7 Professional x64
OS
Windows 7 Professional x64

My Computer My Computer

Computer type
Laptop
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 My Computer

At a glance

Windows 7 Professional x64
OS
Windows 7 Professional x64
Tys, you did put quotes around the source and target for the xcopy????

Rich
 

My Computer My Computer

At a glance

Windows 7 Pro x64 SP1Intel Core I716 GigsNVIDIA GeForce GTX 670M
Computer type
Laptop
Computer Manufacturer/Model Number
Toshiba Laptop Qosimo X870
OS
Windows 7 Pro x64 SP1
CPU
Intel Core I7
Motherboard
Toshiba Qosmio
Memory
16 Gigs
Graphics Card(s)
NVIDIA GeForce GTX 670M
Monitor(s) Displays
17.7" laptop
Screen Resolution
1600 x 900
Hard Drives
256 Gig SanDisk SSD for C
256 Gig Intel SSD for D
Internet Speed
50/25 FIOS
Antivirus
Vipre (all you can eat for 10 machines)
Browser
IE and FF
Other Info
I have dos 6.22, wfwg 3.11, win98, 2000 and xp VHD's available for testing. MS's Virtual PC works great.
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 My Computer

Computer type
Laptop
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 My Computer

At a glance

Windows 7 Professional x64
OS
Windows 7 Professional x64
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 My Computer

At a glance

Windows 7 Pro x64 SP1Intel Core I716 GigsNVIDIA GeForce GTX 670M
Computer type
Laptop
Computer Manufacturer/Model Number
Toshiba Laptop Qosimo X870
OS
Windows 7 Pro x64 SP1
CPU
Intel Core I7
Motherboard
Toshiba Qosmio
Memory
16 Gigs
Graphics Card(s)
NVIDIA GeForce GTX 670M
Monitor(s) Displays
17.7" laptop
Screen Resolution
1600 x 900
Hard Drives
256 Gig SanDisk SSD for C
256 Gig Intel SSD for D
Internet Speed
50/25 FIOS
Antivirus
Vipre (all you can eat for 10 machines)
Browser
IE and FF
Other Info
I have dos 6.22, wfwg 3.11, win98, 2000 and xp VHD's available for testing. MS's Virtual PC works great.
Sorry, I don't understand. Is this a new batch file? Or is this an add on to the existing batch file..?
 

My Computer My Computer

At a glance

Windows 7 Professional x64
OS
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!

Don't you mean you want to do it automatically?
 

My Computer My Computer

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

My Computer My Computer

Computer type
Laptop
sorry, yes, automatically.
 

My Computer My Computer

At a glance

Windows 7 Professional x64
OS
Windows 7 Professional x64
Code:
@echo off
:start
XCOPY "<Source Path>" "<Destination Path>" /f 
TIMEOUT /t 3600 /nobreak
goto start

The batch file should just copy and overwrite the old backup file with the new backup file without waiting for your response, I've left the /f switch so you know which files are being copied.
 

My Computer My Computer

Computer type
Laptop
Thanks!

Nearly there, but it still asks me for "(YES/NO/ALL)". Is there a way to get this script to work automatically without running a Scheduled Task?
 

My Computer My Computer

At a glance

Windows 7 Professional x64
OS
Windows 7 Professional x64
Code:
@echo off
:start
COPY "<Source Path>" "<Destination Path>"
TIMEOUT /t 3600 /nobreak
goto start
I've just tried the batch file out now, and it doesn't prompt for anything, the only problem with COPY command is that it doesn't sub directories I believe.
 

My Computer My Computer

Computer type
Laptop
Yup. lovely it works.


Is there an add-on to this which enables files to be deleted, lets say older than a week?

Thanks!
 

My Computer My Computer

At a glance

Windows 7 Professional x64
OS
Windows 7 Professional x64
Code:
@echo off
DEL [[drive:][path]filename
You wouldn't able to use the Timeout command for a week though, since the command is limited to 99999 seconds, which if I worked it out correctly, is 27 hours.

You would have to create a different batch file, since I don't see how it could be added to the existing batch file without being added to the loop, which would mean your backups would be saved and then deleted every hour.

With the above command, at least you wouldn't have to go searching for the backups.
 

My Computer My Computer

Computer type
Laptop
Back
Top